QListCtrl.cpp 34 KB

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