QListCtrl.cpp 40 KB

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