QListCtrl.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565
  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_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_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_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_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_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>"))) //don't auto delete
  367. {
  368. m_dontDeleteImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  369. rcText.left += m_dontDeleteImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  370. }
  371. if (strSymbols.Find(_T("<shortcut>")) >= 0) // has shortcut
  372. {
  373. m_shortCutImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  374. rcText.left += m_shortCutImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  375. }
  376. if (drawInGroupIcon &&
  377. strSymbols.Find(_T("<ingroup>")) >= 0) // in group
  378. {
  379. m_inFolderImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  380. rcText.left += m_inFolderImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  381. }
  382. if (strSymbols.Find(_T("<qpastetext>")) >= 0) // has quick paste text
  383. {
  384. }
  385. if (strSymbols.Find(_T("<sticky>")) >= 0) //sticky clip
  386. {
  387. m_stickyImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  388. rcText.left += m_stickyImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  389. }
  390. }
  391. if(DrawRtfText(nItem, rcText, pDC) == FALSE)
  392. {
  393. //use unprintable characters so it doesn't find copied html to convert
  394. if (m_searchText.GetLength() > 0 &&
  395. FindNoCaseAndInsert(csText, m_searchText, _T("\x01\x04 color='#ff0000'\x02"), _T("\x01\x03\x04\x02"), m_linesPerRow) > 0)
  396. {
  397. DrawHTML(pDC->m_hDC, csText, csText.GetLength(), rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
  398. }
  399. else
  400. {
  401. pDC->DrawText(csText, rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
  402. }
  403. }
  404. // Draw a focus rect around the item if necessary.
  405. //if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
  406. // pDC->DrawFocusRect(rcItem);
  407. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  408. {
  409. CString cs;
  410. if( firstTenNum == 10 )
  411. cs = "0";
  412. else
  413. cs.Format(_T("%d"), firstTenNum);
  414. CRect crClient;
  415. GetWindowRect(crClient);
  416. ScreenToClient(crClient);
  417. CRect crHotKey = rcItem;
  418. int extraFromClipWasPaste = 0;
  419. if (m_showIfClipWasPasted)
  420. extraFromClipWasPaste = 3;
  421. crHotKey.right = crHotKey.left + theApp.m_metrics.ScaleX(11);
  422. crHotKey.left += theApp.m_metrics.ScaleX(1 + extraFromClipWasPaste);
  423. crHotKey.top += theApp.m_metrics.ScaleX(1 + extraFromClipWasPaste);
  424. HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
  425. COLORREF localOldTextColor = pDC->SetTextColor(g_Opt.m_Theme.ListSmallQuickPasteIndexColor());
  426. CPen pen(PS_SOLID, 0, g_Opt.m_Theme.ListSmallQuickPasteIndexColor());
  427. CPen* pOldPen = pDC->SelectObject(&pen);
  428. pDC->DrawText(cs, crHotKey, DT_BOTTOM);
  429. pDC->MoveTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(8 + extraFromClipWasPaste), rcItem.top));
  430. pDC->LineTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(8 + extraFromClipWasPaste), rcItem.bottom));
  431. pDC->SelectObject(hOldFont);
  432. pDC->SetTextColor(localOldTextColor);
  433. pDC->SelectObject(pOldPen);
  434. }
  435. // restore the previous values
  436. if(OldColor > -1)
  437. pDC->SetTextColor(OldColor);
  438. if(nOldBKMode > -1)
  439. pDC->SetBkMode(nOldBKMode);
  440. *pResult = CDRF_SKIPDEFAULT; // We've painted everything.
  441. }
  442. }
  443. BOOL CQListCtrl::DrawRtfText(int nItem, CRect &crRect, CDC *pDC)
  444. {
  445. if(g_Opt.m_bDrawRTF == FALSE)
  446. return FALSE;
  447. BOOL bRet = FALSE;
  448. CClipFormat* pThumbnail = GetItem_CF_RTF_ClipFormat(nItem);
  449. if(pThumbnail == NULL)
  450. return FALSE;
  451. // if there's no data, then we're done.
  452. if(pThumbnail->m_hgData == NULL)
  453. return FALSE;
  454. if(m_pFormatter == NULL)
  455. {
  456. m_pFormatter = new CFormattedTextDraw;
  457. m_pFormatter->Create();
  458. }
  459. if(m_pFormatter)
  460. {
  461. char *pData = (char*)GlobalLock(pThumbnail->m_hgData);
  462. if(pData)
  463. {
  464. CComBSTR bStr(pData);
  465. m_pFormatter->put_RTFText(bStr);
  466. m_pFormatter->Draw(pDC->m_hDC, crRect);
  467. GlobalUnlock(pThumbnail->m_hgData);
  468. bRet = TRUE;
  469. }
  470. }
  471. return bRet;
  472. }
  473. // DrawBitMap loads a DIB from the DB, draws a crRect thumbnail of the image
  474. // to pDC and caches that thumbnail as a DIB in m_ThumbNails[ ItemID ].
  475. // ALL items are cached in m_ThumbNails (those without images are cached with NULL m_hgData)
  476. BOOL CQListCtrl::DrawBitMap(int nItem, CRect &crRect, CDC *pDC, const CString &csDescription)
  477. {
  478. if(g_Opt.m_bDrawThumbnail == FALSE)
  479. return FALSE;
  480. CClipFormatQListCtrl *format = GetItem_CF_DIB_ClipFormat(nItem);
  481. if(format != NULL)
  482. {
  483. HGLOBAL smallImage = format->GetDib(pDC, crRect.Height());
  484. if(smallImage != NULL)
  485. {
  486. //Will return the width of the bitmap in nWidth
  487. int nWidth = 0;
  488. if(CBitmapHelper::DrawDIB(pDC, smallImage, crRect.left, crRect.top, nWidth))
  489. {
  490. // adjust the rect so other information can be drawn next to the thumbnail
  491. crRect.left += nWidth + 3;
  492. }
  493. }
  494. }
  495. else if(csDescription.Find(_T("CF_DIB")) == 0)
  496. {
  497. crRect.left += crRect.Height();
  498. }
  499. return TRUE;
  500. }
  501. void CQListCtrl::RefreshVisibleRows()
  502. {
  503. int nTopIndex = GetTopIndex();
  504. int nLastIndex = nTopIndex + GetCountPerPage();
  505. RedrawItems(nTopIndex, nLastIndex);
  506. }
  507. void CQListCtrl::RefreshRow(int row)
  508. {
  509. RedrawItems(row, row);
  510. }
  511. void CQListCtrl::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  512. {
  513. CListCtrl::OnSysKeyDown(nChar, nRepCnt, nFlags);
  514. }
  515. BOOL CQListCtrl::OnEraseBkgnd(CDC* pDC)
  516. {
  517. CRect rect;
  518. GetClientRect(&rect);
  519. CBrush myBrush(g_Opt.m_Theme.MainWindowBG()); // dialog background color
  520. CBrush *pOld = pDC->SelectObject(&myBrush);
  521. BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
  522. pDC->SelectObject(pOld); // restore old brush
  523. return bRes; // CDialog::OnEraseBkgnd(pDC);
  524. // Simply returning TRUE seems OK since we do custom item
  525. // painting. However, there is a pixel buffer around the
  526. // border of this control (not within the item rects)
  527. // which becomes visually corrupt if it is not erased.
  528. // In most cases, I do not notice the erasure, so I have kept
  529. // the call to CListCtrl::OnEraseBkgnd(pDC);
  530. // However, for some reason, bulk erasure is very noticeable when
  531. // shift-scrolling the page to select a block of items, so
  532. // I made a special case for that:
  533. //if(GetSelectedCount() >= 2)
  534. // return TRUE;
  535. //return CListCtrl::OnEraseBkgnd(pDC);
  536. }
  537. BOOL CQListCtrl::OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  538. {
  539. // need to handle both ANSI and UNICODE versions of the message
  540. TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
  541. TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
  542. CString strTipText;
  543. UINT_PTR nID = pNMHDR->idFrom;
  544. if(nID == 0) // Notification in NT from automatically
  545. return FALSE; // created tooltip
  546. ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 500);
  547. // Use Item's name as the tool tip. Change this for something different.
  548. // Like use its file size, etc.
  549. GetToolTipText((int)nID-1, strTipText);
  550. //Replace the tabs with spaces, the tooltip didn't like the \t s
  551. strTipText.Replace(_T("\t"), _T(" "));
  552. int nLength = strTipText.GetLength()+2;
  553. #ifndef _UNICODE
  554. if (pNMHDR->code == TTN_NEEDTEXTA)
  555. {
  556. if(m_pchTip != NULL)
  557. delete m_pchTip;
  558. m_pchTip = new TCHAR[nLength];
  559. lstrcpyn(m_pchTip, strTipText, nLength-1);
  560. m_pchTip[nLength-1] = 0;
  561. pTTTW->lpszText = (WCHAR*)m_pchTip;
  562. }
  563. else
  564. {
  565. if(m_pwchTip != NULL)
  566. delete m_pwchTip;
  567. m_pwchTip = new WCHAR[nLength];
  568. _mbstowcsz(m_pwchTip, strTipText, nLength-1);
  569. m_pwchTip[nLength-1] = 0; // end of text
  570. pTTTW->lpszText = (WCHAR*)m_pwchTip;
  571. }
  572. #else
  573. if(pNMHDR->code == TTN_NEEDTEXTA)
  574. {
  575. if(m_pchTip != NULL)
  576. delete m_pchTip;
  577. m_pchTip = new TCHAR[nLength];
  578. STRNCPY(m_pchTip, strTipText, nLength-1);
  579. m_pchTip[nLength-1] = 0; // end of text
  580. pTTTW->lpszText = (LPTSTR)m_pchTip;
  581. }
  582. else
  583. {
  584. if(m_pwchTip != NULL)
  585. delete m_pwchTip;
  586. m_pwchTip = new WCHAR[nLength];
  587. lstrcpyn(m_pwchTip, strTipText, nLength-1);
  588. m_pwchTip[nLength-1] = 0;
  589. pTTTW->lpszText = (LPTSTR) m_pwchTip;
  590. }
  591. #endif
  592. *pResult = 0;
  593. return TRUE; // message was handled
  594. }
  595. INT_PTR CQListCtrl::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
  596. {
  597. CRect rect;
  598. GetClientRect(&rect);
  599. if(rect.PtInRect(point))
  600. {
  601. if(GetItemCount())
  602. {
  603. int nTopIndex = GetTopIndex();
  604. int nBottomIndex = nTopIndex + GetCountPerPage();
  605. if(nBottomIndex > GetItemCount()) nBottomIndex = GetItemCount();
  606. for(int nIndex = nTopIndex; nIndex <= nBottomIndex; nIndex++)
  607. {
  608. GetItemRect(nIndex, rect, LVIR_BOUNDS);
  609. if(rect.PtInRect(point))
  610. {
  611. pTI->hwnd = m_hWnd;
  612. pTI->uId = (UINT)(nIndex+1);
  613. pTI->lpszText = LPSTR_TEXTCALLBACK;
  614. pTI->rect = rect;
  615. pTI->uFlags = TTF_TRANSPARENT;
  616. return pTI->uId;
  617. }
  618. }
  619. }
  620. }
  621. return -1;
  622. }
  623. int CQListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  624. {
  625. if (CListCtrl::OnCreate(lpCreateStruct) == -1)
  626. return -1;
  627. EnableToolTips();
  628. m_pToolTip = new CToolTipEx;
  629. m_pToolTip->Create(this);
  630. m_pToolTip->SetNotifyWnd(GetParent());
  631. return 0;
  632. }
  633. BOOL CQListCtrl::PreTranslateMessage(MSG* pMsg)
  634. {
  635. CAccel a;
  636. if(m_Accels.OnMsg(pMsg, a))
  637. {
  638. switch(a.Cmd)
  639. {
  640. case COPY_BUFFER_HOT_KEY_1_ID:
  641. PutSelectedItemOnDittoCopyBuffer(0);
  642. break;
  643. case COPY_BUFFER_HOT_KEY_2_ID:
  644. PutSelectedItemOnDittoCopyBuffer(1);
  645. break;
  646. case COPY_BUFFER_HOT_KEY_3_ID:
  647. PutSelectedItemOnDittoCopyBuffer(2);
  648. break;
  649. default:
  650. if(a.RefId == CHotKey::PASTE_OPEN_CLIP)
  651. {
  652. GetParent()->SendMessage(NM_SELECT_DB_ID, a.Cmd, 0);
  653. }
  654. else if(a.RefId == CHotKey::MOVE_TO_GROUP)
  655. {
  656. GetParent()->SendMessage(NM_MOVE_TO_GROUP, a.Cmd, 0);
  657. }
  658. }
  659. return TRUE;
  660. }
  661. if(VALID_TOOLTIP)
  662. {
  663. if(m_pToolTip->OnMsg(pMsg))
  664. return TRUE;
  665. }
  666. switch(pMsg->message)
  667. {
  668. case WM_KEYDOWN:
  669. if(HandleKeyDown(pMsg->wParam, pMsg->lParam))
  670. return TRUE;
  671. break; // end case WM_KEYDOWN
  672. case WM_VSCROLL:
  673. ASSERT(FALSE);
  674. break;
  675. } // end switch(pMsg->message)
  676. return CListCtrl::PreTranslateMessage(pMsg);
  677. }
  678. BOOL CQListCtrl::HandleKeyDown(WPARAM wParam, LPARAM lParam)
  679. {
  680. if(VALID_TOOLTIP)
  681. {
  682. MSG Msg;
  683. Msg.lParam = lParam;
  684. Msg.wParam = wParam;
  685. Msg.message = WM_KEYDOWN;
  686. if(m_pToolTip->OnMsg(&Msg))
  687. return TRUE;
  688. }
  689. WPARAM vk = wParam;
  690. switch( vk )
  691. {
  692. case 'X': // Ctrl-X = Cut (prepare for moving the items into a Group)
  693. if(CONTROL_PRESSED)
  694. {
  695. LoadCopyOrCutToClipboard();
  696. theApp.IC_Cut(); // uses selection
  697. return TRUE;
  698. }
  699. break;
  700. case 'C': // Ctrl-C = Copy (prepare for copying the items into a Group)
  701. if(CONTROL_PRESSED)
  702. {
  703. LoadCopyOrCutToClipboard();
  704. theApp.IC_Copy(); // uses selection
  705. return TRUE;
  706. }
  707. break;
  708. case 'V': // Ctrl-V = Paste (actually performs the copy or move of items into the current Group)
  709. if(CONTROL_PRESSED)
  710. {
  711. theApp.IC_Paste();
  712. return TRUE;
  713. }
  714. break;
  715. case 'A': // Ctrl-A = Select All
  716. if(CONTROL_PRESSED)
  717. {
  718. int nCount = GetItemCount();
  719. for(int i = 0; i < nCount; i++)
  720. {
  721. SetSelection(i);
  722. }
  723. return TRUE;
  724. }
  725. break;
  726. case VK_HOME:
  727. SetListPos(0);
  728. break;
  729. } // end switch(vk)
  730. return FALSE;
  731. }
  732. void CQListCtrl::LoadCopyOrCutToClipboard()
  733. {
  734. ARRAY arr;
  735. GetSelectionItemData(arr);
  736. INT_PTR count = arr.GetSize();
  737. if(count <= 0)
  738. return;
  739. CProcessPaste paste;
  740. //Don't send the paste just load it into memory
  741. paste.m_bSendPaste = false;
  742. if(count > 1)
  743. paste.GetClipIDs().Copy(arr);
  744. else
  745. paste.GetClipIDs().Add(arr[0]);
  746. //Don't move these to the top
  747. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  748. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  749. paste.DoPaste();
  750. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  751. }
  752. bool CQListCtrl::PostEventLoadedCheckDescription(int updatedRow)
  753. {
  754. bool loadedClip = false;
  755. if (VALID_TOOLTIP)
  756. {
  757. int toolTipClipId = m_pToolTip->GetClipId();
  758. int toolTipClipRow = m_pToolTip->GetClipRow();
  759. if (toolTipClipRow >= 0)
  760. {
  761. log(StrF(_T("PostEventLoadedCheckDescription refreshRow: %d tt_row: %d tt_id: %d"), updatedRow, toolTipClipRow, toolTipClipId));
  762. }
  763. //We tried to show the clip but we didn't have the id yet, it was loaded in a thread, now it's being updated
  764. //see if we need to show this rows description
  765. if (toolTipClipId <= 0 &&
  766. toolTipClipRow == updatedRow &&
  767. ::IsWindow(m_toolTipHwnd))
  768. {
  769. ShowFullDescription(false, true);
  770. loadedClip = true;
  771. }
  772. }
  773. return loadedClip;
  774. }
  775. bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
  776. {
  777. if (this->GetSelectedCount() == 0)
  778. {
  779. return false;
  780. }
  781. int clipRow = this->GetCaret();
  782. int clipId = this->GetItemData(clipRow);
  783. log(StrF(_T("Show full description row: %d id: %d"), clipRow, clipId));
  784. if(VALID_TOOLTIP &&
  785. clipId > 0 &&
  786. m_pToolTip->GetClipId() == clipId &&
  787. ::IsWindow(m_toolTipHwnd))
  788. {
  789. return false;
  790. }
  791. int nItem = GetCaret();
  792. CRect rc, crWindow;
  793. GetWindowRect(&crWindow);
  794. GetItemRect(nItem, rc, LVIR_BOUNDS);
  795. ClientToScreen(rc);
  796. CPoint pt;
  797. if(CGetSetOptions::GetRememberDescPos())
  798. {
  799. CGetSetOptions::GetDescWndPoint(pt);
  800. }
  801. else if(bFromAuto == false)
  802. {
  803. pt = CPoint(rc.left, rc.bottom);
  804. }
  805. else
  806. {
  807. pt = CPoint((crWindow.left + (crWindow.right - crWindow.left)/2), rc.bottom);
  808. }
  809. CString csDescription;
  810. GetToolTipText(nItem, csDescription);
  811. if (m_pToolTip == NULL ||
  812. fromNextPrev == false ||
  813. ::IsWindow(m_toolTipHwnd) == FALSE)
  814. {
  815. m_pToolTip->DestroyWindow();
  816. m_pToolTip = new CToolTipEx;
  817. m_pToolTip->Create(this);
  818. m_toolTipHwnd = m_pToolTip->GetSafeHwnd();
  819. m_pToolTip->SetNotifyWnd(GetParent());
  820. }
  821. else if(VALID_TOOLTIP)
  822. {
  823. CRect r;
  824. m_pToolTip->GetWindowRect(r);
  825. pt = r.TopLeft();
  826. m_pToolTip->SetBitmap(NULL);
  827. m_pToolTip->SetRTFText("");
  828. m_pToolTip->SetToolTipText(_T(""));
  829. }
  830. if(VALID_TOOLTIP)
  831. {
  832. m_pToolTip->SetClipId(clipId);
  833. m_pToolTip->SetClipRow(clipRow);
  834. m_pToolTip->SetSearchText(m_searchText);
  835. m_pToolTip->SetClipData(_T(""));
  836. m_pToolTip->SetToolTipText(_T(""));
  837. m_pToolTip->SetRTFText(" ");
  838. bool bSetPlainText = false;
  839. CClipFormat Clip;
  840. try
  841. {
  842. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, lDate, lastPasteDate, lDontAutoDelete, QuickPasteText, lShortCut, globalShortCut FROM Main WHERE lID = %d"), clipId);
  843. if (q.eof() == false)
  844. {
  845. CString clipData;
  846. COleDateTime time((time_t)q.getIntField(_T("lDate")));
  847. clipData += "Added: " + time.Format();
  848. COleDateTime modified((time_t)q.getIntField(_T("lastPasteDate")));
  849. clipData += _T(" | Last Used: ") + modified.Format();
  850. if (q.getIntField(_T("lDontAutoDelete")) > 0)
  851. {
  852. clipData += _T(" | Never Auto Delete");
  853. }
  854. CString csQuickPaste = q.getStringField(_T("QuickPasteText"));
  855. if (csQuickPaste.IsEmpty() == FALSE)
  856. {
  857. clipData += _T(" | Quick Paste = ");
  858. clipData += csQuickPaste;
  859. }
  860. int shortCut = q.getIntField(_T("lShortCut"));
  861. if (shortCut > 0)
  862. {
  863. clipData += _T(" | ");
  864. clipData += CHotKey::GetHotKeyDisplayStatic(shortCut);
  865. BOOL globalShortCut = q.getIntField(_T("globalShortCut"));
  866. if (globalShortCut)
  867. {
  868. clipData += _T(" - Global Shortcut Key");
  869. }
  870. }
  871. m_pToolTip->SetClipData(clipData);
  872. }
  873. }
  874. CATCH_SQLITE_EXCEPTION
  875. Clip.m_cfType = CF_UNICODETEXT;
  876. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  877. {
  878. LPVOID pvData = GlobalLock(Clip.m_hgData);
  879. if(pvData)
  880. {
  881. CString csText = (WCHAR*)pvData;
  882. m_pToolTip->SetToolTipText(csText);
  883. bSetPlainText = true;
  884. }
  885. GlobalUnlock(Clip.m_hgData);
  886. Clip.Free();
  887. Clip.Clear();
  888. }
  889. if(bSetPlainText == false)
  890. {
  891. Clip.m_cfType = CF_TEXT;
  892. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  893. {
  894. LPVOID pvData = GlobalLock(Clip.m_hgData);
  895. if(pvData)
  896. {
  897. CString csText = (char*)pvData;
  898. m_pToolTip->SetToolTipText(csText);
  899. bSetPlainText = true;
  900. }
  901. GlobalUnlock(Clip.m_hgData);
  902. Clip.Free();
  903. Clip.Clear();
  904. }
  905. }
  906. if(bSetPlainText == false)
  907. {
  908. m_pToolTip->SetToolTipText(csDescription);
  909. }
  910. Clip.m_cfType = RegisterClipboardFormat(CF_RTF);
  911. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  912. {
  913. LPVOID pvData = GlobalLock(Clip.m_hgData);
  914. if(pvData)
  915. {
  916. m_pToolTip->SetRTFText((char*)pvData);
  917. }
  918. GlobalUnlock(Clip.m_hgData);
  919. Clip.Free();
  920. Clip.Clear();
  921. }
  922. Clip.m_cfType = CF_DIB;
  923. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  924. {
  925. CBitmap *pBitMap = new CBitmap;
  926. if(pBitMap)
  927. {
  928. CRect rcItem;
  929. GetWindowRect(rcItem);
  930. CDC *pDC = GetDC();;
  931. CBitmapHelper::GetCBitmap(&Clip, pDC, pBitMap, MAXINT);
  932. ReleaseDC(pDC);
  933. //Tooltip wnd will release
  934. m_pToolTip->SetBitmap(pBitMap);
  935. }
  936. Clip.Free();
  937. Clip.Clear();
  938. }
  939. m_pToolTip->Show(pt);
  940. }
  941. return true;
  942. }
  943. void CQListCtrl::GetToolTipText(int nItem, CString &csText)
  944. {
  945. CWnd* pParent=GetParent();
  946. if(pParent && (pParent->GetSafeHwnd() != NULL))
  947. {
  948. CQListToolTipText info;
  949. memset(&info, 0, sizeof(info));
  950. info.hdr.code = NM_GETTOOLTIPTEXT;
  951. info.hdr.hwndFrom = GetSafeHwnd();
  952. info.hdr.idFrom = GetDlgCtrlID();
  953. info.lItem = nItem;
  954. //plus 100 for extra info - shortcut and such
  955. info.cchTextMax = g_Opt.m_bDescTextSize + 100;
  956. info.pszText = csText.GetBufferSetLength(info.cchTextMax);
  957. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  958. csText.ReleaseBuffer();
  959. }
  960. }
  961. BOOL CQListCtrl::GetClipData(int nItem, CClipFormat &Clip)
  962. {
  963. return theApp.GetClipData(GetItemData(nItem), Clip);
  964. }
  965. DWORD CQListCtrl::GetItemData(int nItem)
  966. {
  967. if((GetStyle() & LVS_OWNERDATA))
  968. {
  969. CWnd* pParent=GetParent();
  970. if(pParent && (pParent->GetSafeHwnd() != NULL))
  971. {
  972. LV_DISPINFO info;
  973. memset(&info, 0, sizeof(info));
  974. info.hdr.code = LVN_GETDISPINFO;
  975. info.hdr.hwndFrom = GetSafeHwnd();
  976. info.hdr.idFrom = GetDlgCtrlID();
  977. info.item.iItem = nItem;
  978. info.item.lParam = -1;
  979. info.item.mask = LVIF_PARAM;
  980. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  981. return (DWORD)info.item.lParam;
  982. }
  983. }
  984. return (DWORD)CListCtrl::GetItemData(nItem);
  985. }
  986. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_DIB_ClipFormat(int nItem)
  987. {
  988. CClipFormatQListCtrl *format = NULL;
  989. CWnd* pParent=GetParent();
  990. if(pParent && (pParent->GetSafeHwnd() != NULL))
  991. {
  992. LV_DISPINFO info;
  993. memset(&info, 0, sizeof(info));
  994. info.hdr.code = LVN_GETDISPINFO;
  995. info.hdr.hwndFrom = GetSafeHwnd();
  996. info.hdr.idFrom = GetDlgCtrlID();
  997. info.item.iItem = nItem;
  998. info.item.lParam = NULL;
  999. info.item.mask = LVIF_CF_DIB;
  1000. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  1001. if(info.item.lParam != NULL)
  1002. {
  1003. format = (CClipFormatQListCtrl *)info.item.lParam;
  1004. }
  1005. }
  1006. return format;
  1007. }
  1008. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_RTF_ClipFormat(int nItem)
  1009. {
  1010. CClipFormatQListCtrl *format = NULL;
  1011. CWnd* pParent=GetParent();
  1012. if(pParent && (pParent->GetSafeHwnd() != NULL))
  1013. {
  1014. LV_DISPINFO info;
  1015. memset(&info, 0, sizeof(info));
  1016. info.hdr.code = LVN_GETDISPINFO;
  1017. info.hdr.hwndFrom = GetSafeHwnd();
  1018. info.hdr.idFrom = GetDlgCtrlID();
  1019. info.item.iItem = nItem;
  1020. info.item.lParam = NULL;
  1021. info.item.mask = LVIF_CF_RICHTEXT;
  1022. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  1023. if(info.item.lParam != NULL)
  1024. {
  1025. format = (CClipFormatQListCtrl *)info.item.lParam;
  1026. }
  1027. }
  1028. return format;
  1029. }
  1030. void CQListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1031. {
  1032. CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
  1033. }
  1034. void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate, CppSQLite3DB &db)
  1035. {
  1036. m_Accels.RemoveAll();
  1037. if(bCreate)
  1038. {
  1039. CMainTableFunctions::LoadAcceleratorKeys(m_Accels, db);
  1040. LoadDittoCopyBufferHotkeys();
  1041. }
  1042. }
  1043. void CQListCtrl::LoadDittoCopyBufferHotkeys()
  1044. {
  1045. CCopyBufferItem Item;
  1046. CAccel a;
  1047. g_Opt.GetCopyBufferItem(0, Item);
  1048. if(Item.m_lCopyHotKey > 0)
  1049. {
  1050. a.Cmd = COPY_BUFFER_HOT_KEY_1_ID;
  1051. a.Key = Item.m_lCopyHotKey;
  1052. m_Accels.AddAccel(a);
  1053. }
  1054. g_Opt.GetCopyBufferItem(1, Item);
  1055. if(Item.m_lCopyHotKey > 0)
  1056. {
  1057. a.Cmd = COPY_BUFFER_HOT_KEY_2_ID;
  1058. a.Key = Item.m_lCopyHotKey;
  1059. m_Accels.AddAccel(a);
  1060. }
  1061. g_Opt.GetCopyBufferItem(2, Item);
  1062. if(Item.m_lCopyHotKey > 0)
  1063. {
  1064. a.Cmd = COPY_BUFFER_HOT_KEY_3_ID;
  1065. a.Key = Item.m_lCopyHotKey;
  1066. m_Accels.AddAccel(a);
  1067. }
  1068. }
  1069. void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
  1070. {
  1071. CListCtrl::OnKillFocus(pNewWnd);
  1072. //if(FocusOnToolTip() == FALSE)
  1073. //m_pToolTip->Hide();
  1074. }
  1075. HWND CQListCtrl::GetToolTipHWnd()
  1076. {
  1077. if(VALID_TOOLTIP)
  1078. return m_pToolTip->GetSafeHwnd();
  1079. return NULL;
  1080. }
  1081. BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = 0 */)
  1082. {
  1083. return CListCtrl::SetItemCountEx(iCount, dwFlags);
  1084. }
  1085. void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
  1086. {
  1087. NMLISTVIEW *pnmv = (NMLISTVIEW *) pNMHDR;
  1088. if((pnmv->uNewState == 3) ||
  1089. (pnmv->uNewState == 1))
  1090. {
  1091. if (VALID_TOOLTIP &&
  1092. ::IsWindowVisible(m_pToolTip->m_hWnd))
  1093. {
  1094. this->ShowFullDescription(false, true);
  1095. }
  1096. if(g_Opt.m_bAllwaysShowDescription)
  1097. {
  1098. KillTimer(TIMER_SHOW_PROPERTIES);
  1099. SetTimer(TIMER_SHOW_PROPERTIES, 300, NULL);
  1100. }
  1101. if(GetSelectedCount() > 0 )
  1102. theApp.SetStatus(NULL, FALSE);
  1103. }
  1104. if(GetSelectedCount() == this->GetItemCount())
  1105. {
  1106. if(m_allSelected == false)
  1107. {
  1108. Log(StrF(_T("List box Select All")));
  1109. GetParent()->SendMessage(NM_ALL_SELECTED, 0, 0);
  1110. m_allSelected = true;
  1111. }
  1112. }
  1113. else if(m_allSelected == true)
  1114. {
  1115. Log(StrF(_T("List box REMOVED Select All")));
  1116. m_allSelected = false;
  1117. }
  1118. }
  1119. void CQListCtrl::OnTimer(UINT_PTR nIDEvent)
  1120. {
  1121. //http://support.microsoft.com/kb/200054
  1122. //OnTimer() Is Not Called Repeatedly for a List Control
  1123. bool callBase = true;
  1124. switch(nIDEvent)
  1125. {
  1126. case TIMER_SHOW_PROPERTIES:
  1127. {
  1128. if( theApp.m_bShowingQuickPaste )
  1129. ShowFullDescription(true);
  1130. KillTimer(TIMER_SHOW_PROPERTIES);
  1131. callBase = false;
  1132. }
  1133. break;
  1134. case TIMER_HIDE_SCROL:
  1135. {
  1136. CPoint cursorPos;
  1137. GetCursorPos(&cursorPos);
  1138. CRect crWindow;
  1139. this->GetWindowRect(&crWindow);
  1140. //check and see if they moved out of the scroll area
  1141. //If they did tell our parent so
  1142. if(MouseInScrollBarArea(crWindow, cursorPos) == false)
  1143. {
  1144. StopHideScrollBarTimer();
  1145. }
  1146. callBase = false;
  1147. }
  1148. break;
  1149. case TIMER_SHOW_SCROLL:
  1150. {
  1151. CPoint cursorPos;
  1152. GetCursorPos(&cursorPos);
  1153. CRect crWindow;
  1154. this->GetWindowRect(&crWindow);
  1155. //Adjust for the v-scroll bar being off of the screen
  1156. crWindow.right -= theApp.m_metrics.ScaleX(GetSystemMetrics(SM_CXVSCROLL));
  1157. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1158. //Check and see if we are still in the cursor area
  1159. if(MouseInScrollBarArea(crWindow, cursorPos))
  1160. {
  1161. m_timerToHideScrollAreaSet = true;
  1162. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);
  1163. //Start looking to hide the scroll bars
  1164. SetTimer(TIMER_HIDE_SCROL, 1000, NULL);
  1165. }
  1166. KillTimer(TIMER_SHOW_SCROLL);
  1167. callBase = false;
  1168. }
  1169. break;
  1170. }
  1171. if(callBase)
  1172. {
  1173. CListCtrl::OnTimer(nIDEvent);
  1174. }
  1175. }
  1176. void CQListCtrl::SetLogFont(LOGFONT &font)
  1177. {
  1178. m_Font.DeleteObject();
  1179. m_boldFont.DeleteObject();
  1180. m_Font.CreateFontIndirect(&font);
  1181. font.lfWeight = 600;
  1182. m_boldFont.CreateFontIndirect(&font);
  1183. SetFont(&m_Font);
  1184. }
  1185. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1186. {
  1187. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  1188. }
  1189. BOOL CQListCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  1190. {
  1191. return CListCtrl::OnMouseWheel(nFlags, zDelta, pt);
  1192. }
  1193. BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  1194. {
  1195. NMLVCACHEHINT* pcachehint = NULL;
  1196. if(message == WM_NOTIFY)
  1197. {
  1198. NMHDR* phdr = (NMHDR*)lParam;
  1199. switch(phdr->code)
  1200. {
  1201. case LVN_ODCACHEHINT:
  1202. pcachehint= (NMLVCACHEHINT*) phdr;
  1203. GetParent()->SendMessage(NM_FILL_REST_OF_LIST, pcachehint->iFrom, pcachehint->iTo);
  1204. return FALSE;
  1205. }
  1206. }
  1207. return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
  1208. }
  1209. BOOL CQListCtrl::OnItemDeleted(long lID)
  1210. {
  1211. BOOL bRet2 = m_RTFData.RemoveKey(lID);
  1212. return (bRet2);
  1213. }
  1214. void CQListCtrl::OnMouseMove(UINT nFlags, CPoint point)
  1215. {
  1216. if(g_Opt.m_showScrollBar == FALSE)
  1217. {
  1218. CRect crWindow;
  1219. this->GetWindowRect(&crWindow);
  1220. ScreenToClient(&crWindow);
  1221. crWindow.right -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1222. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1223. if(MouseInScrollBarArea(crWindow, point))
  1224. {
  1225. if((GetTickCount() - m_mouseOverScrollAreaStart) > 500)
  1226. {
  1227. SetTimer(TIMER_SHOW_SCROLL, 500, NULL);
  1228. m_mouseOverScrollAreaStart = GetTickCount();
  1229. }
  1230. }
  1231. else
  1232. {
  1233. if(m_timerToHideScrollAreaSet)
  1234. {
  1235. StopHideScrollBarTimer();
  1236. }
  1237. KillTimer(TIMER_SHOW_SCROLL);
  1238. }
  1239. }
  1240. }
  1241. bool CQListCtrl::MouseInScrollBarArea(CRect crWindow, CPoint point)
  1242. {
  1243. CRect crRight(crWindow);
  1244. CRect crBottom(crWindow);
  1245. crRight.left = crRight.right - theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1246. crBottom.top = crBottom.bottom - theApp.m_metrics.ScaleY(::GetSystemMetrics(SM_CYHSCROLL));
  1247. /*CString cs;
  1248. cs.Format(_T("point.x: %d, Width: %d, Height: %d\n"), point.x, crWindow.Width(), crWindow.Height());
  1249. OutputDebugString(cs);*/
  1250. if(crRight.PtInRect(point) || crBottom.PtInRect(point))
  1251. {
  1252. return true;
  1253. }
  1254. return false;
  1255. }
  1256. void CQListCtrl::StopHideScrollBarTimer()
  1257. {
  1258. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
  1259. m_timerToHideScrollAreaSet = false;
  1260. KillTimer(TIMER_HIDE_SCROL);
  1261. }
  1262. void CQListCtrl::SetSearchText(CString text)
  1263. {
  1264. m_searchText = text;
  1265. }
  1266. void CQListCtrl::HidePopup()
  1267. {
  1268. if(VALID_TOOLTIP)
  1269. m_pToolTip->Hide();
  1270. }
  1271. BOOL CQListCtrl::IsToolTipWindowVisible()
  1272. {
  1273. return ::IsWindowVisible(m_toolTipHwnd);
  1274. }
  1275. BOOL CQListCtrl::IsToolTipWindowFocus()
  1276. {
  1277. return ::GetFocus() == m_toolTipHwnd ||
  1278. ::GetParent(::GetFocus()) == m_toolTipHwnd;
  1279. }