QListCtrl.cpp 36 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 2
  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_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_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_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_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_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_SELECTBOUNDS);
  283. COLORREF OldColor = -1;
  284. int nOldBKMode = -1;
  285. CString csText;
  286. LPTSTR lpszText = csText.GetBufferSetLength(g_Opt.m_bDescTextSize);
  287. GetItemText(nItem, 0, lpszText, g_Opt.m_bDescTextSize);
  288. csText.ReleaseBuffer();
  289. // extract symbols
  290. CString strSymbols;
  291. int nSymEnd = csText.Find('|');
  292. if (nSymEnd >= 0)
  293. {
  294. strSymbols = csText.Left(nSymEnd);
  295. csText = csText.Mid(nSymEnd + 1);
  296. }
  297. // Draw the background of the list item. Colors are selected
  298. // according to the item's state.
  299. if(rItem.state & LVIS_SELECTED)
  300. {
  301. if(bListHasFocus)
  302. {
  303. crBkgnd = g_Opt.m_Theme.ListBoxSelectedBG();
  304. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedText());
  305. }
  306. else
  307. {
  308. crBkgnd = g_Opt.m_Theme.ListBoxSelectedNoFocusBG();
  309. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedNoFocusText());
  310. }
  311. }
  312. else
  313. {
  314. //Shade alternating Rows
  315. if((nItem % 2) == 0)
  316. {
  317. crBkgnd = g_Opt.m_Theme.ListBoxOddRowsBG();
  318. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxOddRowsText());
  319. }
  320. else
  321. {
  322. crBkgnd = g_Opt.m_Theme.ListBoxEvenRowsBG();
  323. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxEvenRowsText());
  324. }
  325. }
  326. pDC->FillSolidRect(rcItem, crBkgnd);
  327. nOldBKMode = pDC->SetBkMode(TRANSPARENT);
  328. CRect rcText = rcItem;
  329. rcText.left += ROW_LEFT_BORDER;
  330. rcText.top++;
  331. if (m_showIfClipWasPasted &&
  332. strSymbols.GetLength() > 0 &&
  333. strSymbols.Find(_T("<pasted>")) >= 0) //clip was pasted from ditto
  334. {
  335. CRect pastedRect(rcItem);
  336. pastedRect.left++;
  337. pastedRect.right = rcItem.left + theApp.m_metrics.ScaleX(3);
  338. pDC->FillSolidRect(pastedRect, g_Opt.m_Theme.ClipPastedColor());
  339. rcText.left += theApp.m_metrics.ScaleX(4);
  340. }
  341. // set firstTenNum to the first ten number (1-10) corresponding to
  342. // the current nItem.
  343. // -1 means that nItem is not in the FirstTen block.
  344. int firstTenNum = GetFirstTenNum(nItem);
  345. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  346. {
  347. rcText.left += theApp.m_metrics.ScaleX(12);
  348. }
  349. bool drawInGroupIcon = true;
  350. // if we are inside a group, don't display the "in group" flag
  351. if( theApp.m_GroupID > 0 )
  352. {
  353. int nFlag = strSymbols.Find(_T("<ingroup>"));
  354. if (nFlag >= 0)
  355. drawInGroupIcon = false;
  356. }
  357. DrawBitMap(nItem, rcText, pDC, csText);
  358. // draw the symbol box
  359. if( strSymbols.GetLength() > 0 )
  360. {
  361. if(strSymbols.Find(_T("<group>")) >= 0) //group
  362. {
  363. m_groupFolder.Draw(pDC, this, rcText.left, rcText.top, false, false);
  364. rcText.left += m_groupFolder.ImageWidth() + theApp.m_metrics.ScaleX(2);
  365. }
  366. if (strSymbols.Find(_T("<noautodelete>")) >= 0 &&
  367. strSymbols.Find(_T("<group>")) < 0 &&
  368. strSymbols.Find(_T("<sticky>")) < 0) //don't auto delete
  369. {
  370. m_dontDeleteImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  371. rcText.left += m_dontDeleteImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  372. }
  373. if (strSymbols.Find(_T("<shortcut>")) >= 0) // has shortcut
  374. {
  375. m_shortCutImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  376. rcText.left += m_shortCutImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  377. }
  378. if (drawInGroupIcon &&
  379. strSymbols.Find(_T("<ingroup>")) >= 0) // in group
  380. {
  381. m_inFolderImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  382. rcText.left += m_inFolderImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  383. }
  384. if (strSymbols.Find(_T("<qpastetext>")) >= 0) // has quick paste text
  385. {
  386. }
  387. if (strSymbols.Find(_T("<sticky>")) >= 0) //sticky clip
  388. {
  389. m_stickyImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  390. rcText.left += m_stickyImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  391. }
  392. }
  393. if(DrawRtfText(nItem, rcText, pDC) == FALSE)
  394. {
  395. if (m_searchText.GetLength() > 0 &&
  396. FindNoCaseAndInsert(csText, m_searchText, _T("<font color='#ff0000'>"), _T("</font>"), m_linesPerRow) > 0)
  397. {
  398. DrawHTML(pDC->m_hDC, csText, csText.GetLength(), rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
  399. }
  400. else
  401. {
  402. pDC->DrawText(csText, rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
  403. }
  404. }
  405. // Draw a focus rect around the item if necessary.
  406. //if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
  407. // pDC->DrawFocusRect(rcItem);
  408. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  409. {
  410. CString cs;
  411. if( firstTenNum == 10 )
  412. cs = "0";
  413. else
  414. cs.Format(_T("%d"), firstTenNum);
  415. CRect crClient;
  416. GetWindowRect(crClient);
  417. ScreenToClient(crClient);
  418. CRect crHotKey = rcItem;
  419. int extraFromClipWasPaste = 0;
  420. if (m_showIfClipWasPasted)
  421. extraFromClipWasPaste = 3;
  422. crHotKey.right = crHotKey.left + theApp.m_metrics.ScaleX(11);
  423. crHotKey.left += theApp.m_metrics.ScaleX(1 + extraFromClipWasPaste);
  424. crHotKey.top += theApp.m_metrics.ScaleX(1 + extraFromClipWasPaste);
  425. HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
  426. COLORREF localOldTextColor = pDC->SetTextColor(g_Opt.m_Theme.ListSmallQuickPasteIndexColor());
  427. CPen pen(PS_SOLID, 0, g_Opt.m_Theme.ListSmallQuickPasteIndexColor());
  428. CPen* pOldPen = pDC->SelectObject(&pen);
  429. pDC->DrawText(cs, crHotKey, DT_BOTTOM);
  430. pDC->MoveTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(8 + extraFromClipWasPaste), rcItem.top));
  431. pDC->LineTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(8 + extraFromClipWasPaste), rcItem.bottom));
  432. pDC->SelectObject(hOldFont);
  433. pDC->SetTextColor(localOldTextColor);
  434. pDC->SelectObject(pOldPen);
  435. }
  436. // restore the previous values
  437. if(OldColor > -1)
  438. pDC->SetTextColor(OldColor);
  439. if(nOldBKMode > -1)
  440. pDC->SetBkMode(nOldBKMode);
  441. *pResult = CDRF_SKIPDEFAULT; // We've painted everything.
  442. }
  443. }
  444. BOOL CQListCtrl::DrawRtfText(int nItem, CRect &crRect, CDC *pDC)
  445. {
  446. if(g_Opt.m_bDrawRTF == FALSE)
  447. return FALSE;
  448. BOOL bRet = FALSE;
  449. CClipFormat* pThumbnail = GetItem_CF_RTF_ClipFormat(nItem);
  450. if(pThumbnail == NULL)
  451. return FALSE;
  452. // if there's no data, then we're done.
  453. if(pThumbnail->m_hgData == NULL)
  454. return FALSE;
  455. if(m_pFormatter == NULL)
  456. {
  457. m_pFormatter = new CFormattedTextDraw;
  458. m_pFormatter->Create();
  459. }
  460. if(m_pFormatter)
  461. {
  462. char *pData = (char*)GlobalLock(pThumbnail->m_hgData);
  463. if(pData)
  464. {
  465. CComBSTR bStr(pData);
  466. m_pFormatter->put_RTFText(bStr);
  467. m_pFormatter->Draw(pDC->m_hDC, crRect);
  468. GlobalUnlock(pThumbnail->m_hgData);
  469. bRet = TRUE;
  470. }
  471. }
  472. return bRet;
  473. }
  474. // DrawBitMap loads a DIB from the DB, draws a crRect thumbnail of the image
  475. // to pDC and caches that thumbnail as a DIB in m_ThumbNails[ ItemID ].
  476. // ALL items are cached in m_ThumbNails (those without images are cached with NULL m_hgData)
  477. BOOL CQListCtrl::DrawBitMap(int nItem, CRect &crRect, CDC *pDC, const CString &csDescription)
  478. {
  479. if(g_Opt.m_bDrawThumbnail == FALSE)
  480. return FALSE;
  481. CClipFormatQListCtrl *format = GetItem_CF_DIB_ClipFormat(nItem);
  482. if(format != NULL)
  483. {
  484. HGLOBAL smallImage = format->GetDib(pDC, crRect.Height());
  485. if(smallImage != NULL)
  486. {
  487. //Will return the width of the bitmap in nWidth
  488. int nWidth = 0;
  489. if(CBitmapHelper::DrawDIB(pDC, smallImage, crRect.left, crRect.top, nWidth))
  490. {
  491. // adjust the rect so other information can be drawn next to the thumbnail
  492. crRect.left += nWidth + 3;
  493. }
  494. }
  495. }
  496. else if(csDescription.Find(_T("CF_DIB")) == 0)
  497. {
  498. crRect.left += crRect.Height();
  499. }
  500. return TRUE;
  501. }
  502. void CQListCtrl::RefreshVisibleRows()
  503. {
  504. int nTopIndex = GetTopIndex();
  505. int nLastIndex = nTopIndex + GetCountPerPage();
  506. RedrawItems(nTopIndex, nLastIndex);
  507. }
  508. void CQListCtrl::RefreshRow(int row)
  509. {
  510. RedrawItems(row, row);
  511. }
  512. void CQListCtrl::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  513. {
  514. CListCtrl::OnSysKeyDown(nChar, nRepCnt, nFlags);
  515. }
  516. BOOL CQListCtrl::OnEraseBkgnd(CDC* pDC)
  517. {
  518. CRect rect;
  519. GetClientRect(&rect);
  520. CBrush myBrush(g_Opt.m_Theme.MainWindowBG()); // dialog background color
  521. CBrush *pOld = pDC->SelectObject(&myBrush);
  522. BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
  523. pDC->SelectObject(pOld); // restore old brush
  524. return bRes; // CDialog::OnEraseBkgnd(pDC);
  525. // Simply returning TRUE seems OK since we do custom item
  526. // painting. However, there is a pixel buffer around the
  527. // border of this control (not within the item rects)
  528. // which becomes visually corrupt if it is not erased.
  529. // In most cases, I do not notice the erasure, so I have kept
  530. // the call to CListCtrl::OnEraseBkgnd(pDC);
  531. // However, for some reason, bulk erasure is very noticeable when
  532. // shift-scrolling the page to select a block of items, so
  533. // I made a special case for that:
  534. //if(GetSelectedCount() >= 2)
  535. // return TRUE;
  536. //return CListCtrl::OnEraseBkgnd(pDC);
  537. }
  538. BOOL CQListCtrl::OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  539. {
  540. // need to handle both ANSI and UNICODE versions of the message
  541. TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
  542. TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
  543. CString strTipText;
  544. UINT_PTR nID = pNMHDR->idFrom;
  545. if(nID == 0) // Notification in NT from automatically
  546. return FALSE; // created tooltip
  547. ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 500);
  548. // Use Item's name as the tool tip. Change this for something different.
  549. // Like use its file size, etc.
  550. GetToolTipText((int)nID-1, strTipText);
  551. //Replace the tabs with spaces, the tooltip didn't like the \t s
  552. strTipText.Replace(_T("\t"), _T(" "));
  553. int nLength = strTipText.GetLength()+2;
  554. #ifndef _UNICODE
  555. if (pNMHDR->code == TTN_NEEDTEXTA)
  556. {
  557. if(m_pchTip != NULL)
  558. delete m_pchTip;
  559. m_pchTip = new TCHAR[nLength];
  560. lstrcpyn(m_pchTip, strTipText, nLength-1);
  561. m_pchTip[nLength-1] = 0;
  562. pTTTW->lpszText = (WCHAR*)m_pchTip;
  563. }
  564. else
  565. {
  566. if(m_pwchTip != NULL)
  567. delete m_pwchTip;
  568. m_pwchTip = new WCHAR[nLength];
  569. _mbstowcsz(m_pwchTip, strTipText, nLength-1);
  570. m_pwchTip[nLength-1] = 0; // end of text
  571. pTTTW->lpszText = (WCHAR*)m_pwchTip;
  572. }
  573. #else
  574. if(pNMHDR->code == TTN_NEEDTEXTA)
  575. {
  576. if(m_pchTip != NULL)
  577. delete m_pchTip;
  578. m_pchTip = new TCHAR[nLength];
  579. STRNCPY(m_pchTip, strTipText, nLength-1);
  580. m_pchTip[nLength-1] = 0; // end of text
  581. pTTTW->lpszText = (LPTSTR)m_pchTip;
  582. }
  583. else
  584. {
  585. if(m_pwchTip != NULL)
  586. delete m_pwchTip;
  587. m_pwchTip = new WCHAR[nLength];
  588. lstrcpyn(m_pwchTip, strTipText, nLength-1);
  589. m_pwchTip[nLength-1] = 0;
  590. pTTTW->lpszText = (LPTSTR) m_pwchTip;
  591. }
  592. #endif
  593. *pResult = 0;
  594. return TRUE; // message was handled
  595. }
  596. INT_PTR CQListCtrl::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
  597. {
  598. CRect rect;
  599. GetClientRect(&rect);
  600. if(rect.PtInRect(point))
  601. {
  602. if(GetItemCount())
  603. {
  604. int nTopIndex = GetTopIndex();
  605. int nBottomIndex = nTopIndex + GetCountPerPage();
  606. if(nBottomIndex > GetItemCount()) nBottomIndex = GetItemCount();
  607. for(int nIndex = nTopIndex; nIndex <= nBottomIndex; nIndex++)
  608. {
  609. GetItemRect(nIndex, rect, LVIR_BOUNDS);
  610. if(rect.PtInRect(point))
  611. {
  612. pTI->hwnd = m_hWnd;
  613. pTI->uId = (UINT)(nIndex+1);
  614. pTI->lpszText = LPSTR_TEXTCALLBACK;
  615. pTI->rect = rect;
  616. pTI->uFlags = TTF_TRANSPARENT;
  617. return pTI->uId;
  618. }
  619. }
  620. }
  621. }
  622. return -1;
  623. }
  624. int CQListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  625. {
  626. if (CListCtrl::OnCreate(lpCreateStruct) == -1)
  627. return -1;
  628. EnableToolTips();
  629. m_pToolTip = new CToolTipEx;
  630. m_pToolTip->Create(this);
  631. m_pToolTip->SetNotifyWnd(GetParent());
  632. return 0;
  633. }
  634. BOOL CQListCtrl::PreTranslateMessage(MSG* pMsg)
  635. {
  636. CAccel a;
  637. if(m_Accels.OnMsg(pMsg, a))
  638. {
  639. switch(a.Cmd)
  640. {
  641. case COPY_BUFFER_HOT_KEY_1_ID:
  642. PutSelectedItemOnDittoCopyBuffer(0);
  643. break;
  644. case COPY_BUFFER_HOT_KEY_2_ID:
  645. PutSelectedItemOnDittoCopyBuffer(1);
  646. break;
  647. case COPY_BUFFER_HOT_KEY_3_ID:
  648. PutSelectedItemOnDittoCopyBuffer(2);
  649. break;
  650. default:
  651. if(a.RefId == CHotKey::PASTE_OPEN_CLIP)
  652. {
  653. GetParent()->SendMessage(NM_SELECT_DB_ID, a.Cmd, 0);
  654. }
  655. else if(a.RefId == CHotKey::MOVE_TO_GROUP)
  656. {
  657. GetParent()->SendMessage(NM_MOVE_TO_GROUP, a.Cmd, 0);
  658. }
  659. }
  660. return TRUE;
  661. }
  662. if(VALID_TOOLTIP)
  663. {
  664. if(m_pToolTip->OnMsg(pMsg))
  665. return TRUE;
  666. }
  667. switch(pMsg->message)
  668. {
  669. case WM_KEYDOWN:
  670. if(HandleKeyDown(pMsg->wParam, pMsg->lParam))
  671. return TRUE;
  672. break; // end case WM_KEYDOWN
  673. case WM_VSCROLL:
  674. ASSERT(FALSE);
  675. break;
  676. } // end switch(pMsg->message)
  677. return CListCtrl::PreTranslateMessage(pMsg);
  678. }
  679. BOOL CQListCtrl::HandleKeyDown(WPARAM wParam, LPARAM lParam)
  680. {
  681. if(VALID_TOOLTIP)
  682. {
  683. MSG Msg;
  684. Msg.lParam = lParam;
  685. Msg.wParam = wParam;
  686. Msg.message = WM_KEYDOWN;
  687. if(m_pToolTip->OnMsg(&Msg))
  688. return TRUE;
  689. }
  690. WPARAM vk = wParam;
  691. switch( vk )
  692. {
  693. case 'X': // Ctrl-X = Cut (prepare for moving the items into a Group)
  694. if(CONTROL_PRESSED)
  695. {
  696. LoadCopyOrCutToClipboard();
  697. theApp.IC_Cut(); // uses selection
  698. return TRUE;
  699. }
  700. break;
  701. case 'C': // Ctrl-C = Copy (prepare for copying the items into a Group)
  702. if(CONTROL_PRESSED)
  703. {
  704. LoadCopyOrCutToClipboard();
  705. theApp.IC_Copy(); // uses selection
  706. return TRUE;
  707. }
  708. break;
  709. case 'V': // Ctrl-V = Paste (actually performs the copy or move of items into the current Group)
  710. if(CONTROL_PRESSED)
  711. {
  712. theApp.IC_Paste();
  713. return TRUE;
  714. }
  715. break;
  716. case 'A': // Ctrl-A = Select All
  717. if(CONTROL_PRESSED)
  718. {
  719. int nCount = GetItemCount();
  720. for(int i = 0; i < nCount; i++)
  721. {
  722. SetSelection(i);
  723. }
  724. return TRUE;
  725. }
  726. break;
  727. case VK_HOME:
  728. SetListPos(0);
  729. break;
  730. } // end switch(vk)
  731. return FALSE;
  732. }
  733. void CQListCtrl::LoadCopyOrCutToClipboard()
  734. {
  735. ARRAY arr;
  736. GetSelectionItemData(arr);
  737. INT_PTR count = arr.GetSize();
  738. if(count <= 0)
  739. return;
  740. CProcessPaste paste;
  741. //Don't send the paste just load it into memory
  742. paste.m_bSendPaste = false;
  743. if(count > 1)
  744. paste.GetClipIDs().Copy(arr);
  745. else
  746. paste.GetClipIDs().Add(arr[0]);
  747. //Don't move these to the top
  748. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  749. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  750. paste.DoPaste();
  751. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  752. }
  753. bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
  754. {
  755. if (this->GetSelectedCount() == 0)
  756. {
  757. return false;
  758. }
  759. int clipId = this->GetItemData(this->GetCaret());
  760. if(VALID_TOOLTIP &&
  761. m_pToolTip->GetClipId() == clipId &&
  762. ::IsWindow(m_toolTipHwnd))
  763. {
  764. return false;
  765. }
  766. int nItem = GetCaret();
  767. CRect rc, crWindow;
  768. GetWindowRect(&crWindow);
  769. GetItemRect(nItem, rc, LVIR_BOUNDS);
  770. ClientToScreen(rc);
  771. CPoint pt;
  772. if(CGetSetOptions::GetRememberDescPos())
  773. {
  774. CGetSetOptions::GetDescWndPoint(pt);
  775. }
  776. else if(bFromAuto == false)
  777. {
  778. pt = CPoint(rc.left, rc.bottom);
  779. }
  780. else
  781. {
  782. pt = CPoint((crWindow.left + (crWindow.right - crWindow.left)/2), rc.bottom);
  783. }
  784. CString csDescription;
  785. GetToolTipText(nItem, csDescription);
  786. if (m_pToolTip == NULL ||
  787. fromNextPrev == false ||
  788. ::IsWindow(m_toolTipHwnd) == FALSE)
  789. {
  790. m_pToolTip->DestroyWindow();
  791. m_pToolTip = new CToolTipEx;
  792. m_pToolTip->Create(this);
  793. m_toolTipHwnd = m_pToolTip->GetSafeHwnd();
  794. m_pToolTip->SetNotifyWnd(GetParent());
  795. }
  796. else if(VALID_TOOLTIP)
  797. {
  798. CRect r;
  799. m_pToolTip->GetWindowRect(r);
  800. pt = r.TopLeft();
  801. m_pToolTip->SetBitmap(NULL);
  802. m_pToolTip->SetRTFText("");
  803. m_pToolTip->SetToolTipText(_T(""));
  804. }
  805. if(VALID_TOOLTIP)
  806. {
  807. m_pToolTip->SetClipId(clipId);
  808. m_pToolTip->SetSearchText(m_searchText);
  809. m_pToolTip->SetToolTipText(_T(""));
  810. m_pToolTip->SetRTFText(" ");
  811. bool bSetPlainText = false;
  812. CClipFormat Clip;
  813. Clip.m_cfType = CF_UNICODETEXT;
  814. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  815. {
  816. LPVOID pvData = GlobalLock(Clip.m_hgData);
  817. if(pvData)
  818. {
  819. CString csText = (WCHAR*)pvData;
  820. m_pToolTip->SetToolTipText(csText);
  821. bSetPlainText = true;
  822. }
  823. GlobalUnlock(Clip.m_hgData);
  824. Clip.Free();
  825. Clip.Clear();
  826. }
  827. if(bSetPlainText == false)
  828. {
  829. Clip.m_cfType = CF_TEXT;
  830. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  831. {
  832. LPVOID pvData = GlobalLock(Clip.m_hgData);
  833. if(pvData)
  834. {
  835. CString csText = (char*)pvData;
  836. m_pToolTip->SetToolTipText(csText);
  837. bSetPlainText = true;
  838. }
  839. GlobalUnlock(Clip.m_hgData);
  840. Clip.Free();
  841. Clip.Clear();
  842. }
  843. }
  844. if(bSetPlainText == false)
  845. {
  846. m_pToolTip->SetToolTipText(csDescription);
  847. }
  848. Clip.m_cfType = RegisterClipboardFormat(CF_RTF);
  849. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  850. {
  851. LPVOID pvData = GlobalLock(Clip.m_hgData);
  852. if(pvData)
  853. {
  854. m_pToolTip->SetRTFText((char*)pvData);
  855. }
  856. GlobalUnlock(Clip.m_hgData);
  857. Clip.Free();
  858. Clip.Clear();
  859. }
  860. Clip.m_cfType = CF_DIB;
  861. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  862. {
  863. CBitmap *pBitMap = new CBitmap;
  864. if(pBitMap)
  865. {
  866. CRect rcItem;
  867. GetWindowRect(rcItem);
  868. CDC *pDC = GetDC();;
  869. CBitmapHelper::GetCBitmap(&Clip, pDC, pBitMap, MAXINT);
  870. ReleaseDC(pDC);
  871. //Tooltip wnd will release
  872. m_pToolTip->SetBitmap(pBitMap);
  873. }
  874. Clip.Free();
  875. Clip.Clear();
  876. }
  877. m_pToolTip->Show(pt);
  878. }
  879. return true;
  880. }
  881. void CQListCtrl::GetToolTipText(int nItem, CString &csText)
  882. {
  883. CWnd* pParent=GetParent();
  884. if(pParent && (pParent->GetSafeHwnd() != NULL))
  885. {
  886. CQListToolTipText info;
  887. memset(&info, 0, sizeof(info));
  888. info.hdr.code = NM_GETTOOLTIPTEXT;
  889. info.hdr.hwndFrom = GetSafeHwnd();
  890. info.hdr.idFrom = GetDlgCtrlID();
  891. info.lItem = nItem;
  892. //plus 100 for extra info - shortcut and such
  893. info.cchTextMax = g_Opt.m_bDescTextSize + 100;
  894. info.pszText = csText.GetBufferSetLength(info.cchTextMax);
  895. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  896. csText.ReleaseBuffer();
  897. }
  898. }
  899. BOOL CQListCtrl::GetClipData(int nItem, CClipFormat &Clip)
  900. {
  901. return theApp.GetClipData(GetItemData(nItem), Clip);
  902. }
  903. DWORD CQListCtrl::GetItemData(int nItem)
  904. {
  905. if((GetStyle() & LVS_OWNERDATA))
  906. {
  907. CWnd* pParent=GetParent();
  908. if(pParent && (pParent->GetSafeHwnd() != NULL))
  909. {
  910. LV_DISPINFO info;
  911. memset(&info, 0, sizeof(info));
  912. info.hdr.code = LVN_GETDISPINFO;
  913. info.hdr.hwndFrom = GetSafeHwnd();
  914. info.hdr.idFrom = GetDlgCtrlID();
  915. info.item.iItem = nItem;
  916. info.item.lParam = -1;
  917. info.item.mask = LVIF_PARAM;
  918. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  919. return (DWORD)info.item.lParam;
  920. }
  921. }
  922. return (DWORD)CListCtrl::GetItemData(nItem);
  923. }
  924. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_DIB_ClipFormat(int nItem)
  925. {
  926. CClipFormatQListCtrl *format = NULL;
  927. CWnd* pParent=GetParent();
  928. if(pParent && (pParent->GetSafeHwnd() != NULL))
  929. {
  930. LV_DISPINFO info;
  931. memset(&info, 0, sizeof(info));
  932. info.hdr.code = LVN_GETDISPINFO;
  933. info.hdr.hwndFrom = GetSafeHwnd();
  934. info.hdr.idFrom = GetDlgCtrlID();
  935. info.item.iItem = nItem;
  936. info.item.lParam = NULL;
  937. info.item.mask = LVIF_CF_DIB;
  938. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  939. if(info.item.lParam != NULL)
  940. {
  941. format = (CClipFormatQListCtrl *)info.item.lParam;
  942. }
  943. }
  944. return format;
  945. }
  946. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_RTF_ClipFormat(int nItem)
  947. {
  948. CClipFormatQListCtrl *format = NULL;
  949. CWnd* pParent=GetParent();
  950. if(pParent && (pParent->GetSafeHwnd() != NULL))
  951. {
  952. LV_DISPINFO info;
  953. memset(&info, 0, sizeof(info));
  954. info.hdr.code = LVN_GETDISPINFO;
  955. info.hdr.hwndFrom = GetSafeHwnd();
  956. info.hdr.idFrom = GetDlgCtrlID();
  957. info.item.iItem = nItem;
  958. info.item.lParam = NULL;
  959. info.item.mask = LVIF_CF_RICHTEXT;
  960. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  961. if(info.item.lParam != NULL)
  962. {
  963. format = (CClipFormatQListCtrl *)info.item.lParam;
  964. }
  965. }
  966. return format;
  967. }
  968. void CQListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  969. {
  970. CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
  971. }
  972. void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate, CppSQLite3DB &db)
  973. {
  974. m_Accels.RemoveAll();
  975. if(bCreate)
  976. {
  977. CMainTableFunctions::LoadAcceleratorKeys(m_Accels, db);
  978. LoadDittoCopyBufferHotkeys();
  979. }
  980. }
  981. void CQListCtrl::LoadDittoCopyBufferHotkeys()
  982. {
  983. CCopyBufferItem Item;
  984. CAccel a;
  985. g_Opt.GetCopyBufferItem(0, Item);
  986. if(Item.m_lCopyHotKey > 0)
  987. {
  988. a.Cmd = COPY_BUFFER_HOT_KEY_1_ID;
  989. a.Key = Item.m_lCopyHotKey;
  990. m_Accels.AddAccel(a);
  991. }
  992. g_Opt.GetCopyBufferItem(1, Item);
  993. if(Item.m_lCopyHotKey > 0)
  994. {
  995. a.Cmd = COPY_BUFFER_HOT_KEY_2_ID;
  996. a.Key = Item.m_lCopyHotKey;
  997. m_Accels.AddAccel(a);
  998. }
  999. g_Opt.GetCopyBufferItem(2, Item);
  1000. if(Item.m_lCopyHotKey > 0)
  1001. {
  1002. a.Cmd = COPY_BUFFER_HOT_KEY_3_ID;
  1003. a.Key = Item.m_lCopyHotKey;
  1004. m_Accels.AddAccel(a);
  1005. }
  1006. }
  1007. void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
  1008. {
  1009. CListCtrl::OnKillFocus(pNewWnd);
  1010. //if(FocusOnToolTip() == FALSE)
  1011. //m_pToolTip->Hide();
  1012. }
  1013. HWND CQListCtrl::GetToolTipHWnd()
  1014. {
  1015. if(VALID_TOOLTIP)
  1016. return m_pToolTip->GetSafeHwnd();
  1017. return NULL;
  1018. }
  1019. BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = 0 */)
  1020. {
  1021. return CListCtrl::SetItemCountEx(iCount, dwFlags);
  1022. }
  1023. void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
  1024. {
  1025. NMLISTVIEW *pnmv = (NMLISTVIEW *) pNMHDR;
  1026. if((pnmv->uNewState == 3) ||
  1027. (pnmv->uNewState == 1))
  1028. {
  1029. if (VALID_TOOLTIP &&
  1030. ::IsWindowVisible(m_pToolTip->m_hWnd))
  1031. {
  1032. this->ShowFullDescription(false, true);
  1033. }
  1034. if(g_Opt.m_bAllwaysShowDescription)
  1035. {
  1036. KillTimer(TIMER_SHOW_PROPERTIES);
  1037. SetTimer(TIMER_SHOW_PROPERTIES, 300, NULL);
  1038. }
  1039. if(GetSelectedCount() > 0 )
  1040. theApp.SetStatus(NULL, FALSE);
  1041. }
  1042. if(GetSelectedCount() == this->GetItemCount())
  1043. {
  1044. if(m_allSelected == false)
  1045. {
  1046. Log(StrF(_T("List box Select All")));
  1047. GetParent()->SendMessage(NM_ALL_SELECTED, 0, 0);
  1048. m_allSelected = true;
  1049. }
  1050. }
  1051. else if(m_allSelected == true)
  1052. {
  1053. Log(StrF(_T("List box REMOVED Select All")));
  1054. m_allSelected = false;
  1055. }
  1056. }
  1057. void CQListCtrl::OnTimer(UINT_PTR nIDEvent)
  1058. {
  1059. //http://support.microsoft.com/kb/200054
  1060. //OnTimer() Is Not Called Repeatedly for a List Control
  1061. bool callBase = true;
  1062. switch(nIDEvent)
  1063. {
  1064. case TIMER_SHOW_PROPERTIES:
  1065. {
  1066. if( theApp.m_bShowingQuickPaste )
  1067. ShowFullDescription(true);
  1068. KillTimer(TIMER_SHOW_PROPERTIES);
  1069. callBase = false;
  1070. }
  1071. break;
  1072. case TIMER_HIDE_SCROL:
  1073. {
  1074. CPoint cursorPos;
  1075. GetCursorPos(&cursorPos);
  1076. CRect crWindow;
  1077. this->GetWindowRect(&crWindow);
  1078. //check and see if they moved out of the scroll area
  1079. //If they did tell our parent so
  1080. if(MouseInScrollBarArea(crWindow, cursorPos) == false)
  1081. {
  1082. StopHideScrollBarTimer();
  1083. }
  1084. callBase = false;
  1085. }
  1086. break;
  1087. case TIMER_SHOW_SCROLL:
  1088. {
  1089. CPoint cursorPos;
  1090. GetCursorPos(&cursorPos);
  1091. CRect crWindow;
  1092. this->GetWindowRect(&crWindow);
  1093. //Adjust for the v-scroll bar being off of the screen
  1094. crWindow.right -= theApp.m_metrics.ScaleX(GetSystemMetrics(SM_CXVSCROLL));
  1095. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1096. //Check and see if we are still in the cursor area
  1097. if(MouseInScrollBarArea(crWindow, cursorPos))
  1098. {
  1099. m_timerToHideScrollAreaSet = true;
  1100. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);
  1101. //Start looking to hide the scroll bars
  1102. SetTimer(TIMER_HIDE_SCROL, 1000, NULL);
  1103. }
  1104. KillTimer(TIMER_SHOW_SCROLL);
  1105. callBase = false;
  1106. }
  1107. break;
  1108. }
  1109. if(callBase)
  1110. {
  1111. CListCtrl::OnTimer(nIDEvent);
  1112. }
  1113. }
  1114. void CQListCtrl::SetLogFont(LOGFONT &font)
  1115. {
  1116. m_Font.DeleteObject();
  1117. m_boldFont.DeleteObject();
  1118. m_Font.CreateFontIndirect(&font);
  1119. font.lfWeight = 600;
  1120. m_boldFont.CreateFontIndirect(&font);
  1121. SetFont(&m_Font);
  1122. }
  1123. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1124. {
  1125. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  1126. }
  1127. BOOL CQListCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  1128. {
  1129. return CListCtrl::OnMouseWheel(nFlags, zDelta, pt);
  1130. }
  1131. BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  1132. {
  1133. NMLVCACHEHINT* pcachehint = NULL;
  1134. if(message == WM_NOTIFY)
  1135. {
  1136. NMHDR* phdr = (NMHDR*)lParam;
  1137. switch(phdr->code)
  1138. {
  1139. case LVN_ODCACHEHINT:
  1140. pcachehint= (NMLVCACHEHINT*) phdr;
  1141. GetParent()->SendMessage(NM_FILL_REST_OF_LIST, pcachehint->iFrom, pcachehint->iTo);
  1142. return FALSE;
  1143. }
  1144. }
  1145. return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
  1146. }
  1147. BOOL CQListCtrl::OnItemDeleted(long lID)
  1148. {
  1149. BOOL bRet2 = m_RTFData.RemoveKey(lID);
  1150. return (bRet2);
  1151. }
  1152. void CQListCtrl::OnMouseMove(UINT nFlags, CPoint point)
  1153. {
  1154. if(g_Opt.m_showScrollBar == FALSE)
  1155. {
  1156. CRect crWindow;
  1157. this->GetWindowRect(&crWindow);
  1158. ScreenToClient(&crWindow);
  1159. crWindow.right -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1160. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1161. if(MouseInScrollBarArea(crWindow, point))
  1162. {
  1163. if((GetTickCount() - m_mouseOverScrollAreaStart) > 500)
  1164. {
  1165. SetTimer(TIMER_SHOW_SCROLL, 500, NULL);
  1166. m_mouseOverScrollAreaStart = GetTickCount();
  1167. }
  1168. }
  1169. else
  1170. {
  1171. if(m_timerToHideScrollAreaSet)
  1172. {
  1173. StopHideScrollBarTimer();
  1174. }
  1175. KillTimer(TIMER_SHOW_SCROLL);
  1176. }
  1177. }
  1178. }
  1179. bool CQListCtrl::MouseInScrollBarArea(CRect crWindow, CPoint point)
  1180. {
  1181. CRect crRight(crWindow);
  1182. CRect crBottom(crWindow);
  1183. crRight.left = crRight.right - theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1184. crBottom.top = crBottom.bottom - theApp.m_metrics.ScaleY(::GetSystemMetrics(SM_CYHSCROLL));
  1185. /*CString cs;
  1186. cs.Format(_T("point.x: %d, Width: %d, Height: %d\n"), point.x, crWindow.Width(), crWindow.Height());
  1187. OutputDebugString(cs);*/
  1188. if(crRight.PtInRect(point) || crBottom.PtInRect(point))
  1189. {
  1190. return true;
  1191. }
  1192. return false;
  1193. }
  1194. void CQListCtrl::StopHideScrollBarTimer()
  1195. {
  1196. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
  1197. m_timerToHideScrollAreaSet = false;
  1198. KillTimer(TIMER_HIDE_SCROL);
  1199. }
  1200. void CQListCtrl::SetSearchText(CString text)
  1201. {
  1202. m_searchText = text;
  1203. }
  1204. void CQListCtrl::HidePopup()
  1205. {
  1206. if(VALID_TOOLTIP)
  1207. m_pToolTip->Hide();
  1208. }
  1209. BOOL CQListCtrl::IsToolTipWindowVisible()
  1210. {
  1211. return ::IsWindowVisible(m_toolTipHwnd);
  1212. }
  1213. BOOL CQListCtrl::IsToolTipWindowFocus()
  1214. {
  1215. return ::GetFocus() == m_toolTipHwnd ||
  1216. ::GetParent(::GetFocus()) == m_toolTipHwnd;
  1217. }