QListCtrl.cpp 32 KB

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