QListCtrl.cpp 34 KB

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