QListCtrl.cpp 39 KB

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