QListCtrl.cpp 35 KB

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