QListCtrl.cpp 34 KB

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