QListCtrl.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  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 = CTextConvert::Utf8ToUnicode(Clip.GetAsCStringA());
  906. m_pToolTip->SetHtmlText(html);
  907. Clip.Free();
  908. Clip.Clear();
  909. }
  910. Clip.m_cfType = CF_DIB;
  911. if (GetClipData(nItem, Clip) && Clip.m_hgData)
  912. {
  913. m_pToolTip->SetGdiplusBitmap(Clip.CreateGdiplusBitmap());
  914. }
  915. else
  916. {
  917. Clip.m_cfType = theApp.m_PNG_Format;
  918. if (GetClipData(nItem, Clip) && Clip.m_hgData)
  919. {
  920. m_pToolTip->SetGdiplusBitmap(Clip.CreateGdiplusBitmap());
  921. }
  922. }
  923. m_pToolTip->Show(pt);
  924. }
  925. return true;
  926. }
  927. void CQListCtrl::GetToolTipText(int nItem, CString &csText)
  928. {
  929. CWnd* pParent = GetParent();
  930. if (pParent && (pParent->GetSafeHwnd() != NULL))
  931. {
  932. CQListToolTipText info;
  933. memset(&info, 0, sizeof(info));
  934. info.hdr.code = NM_GETTOOLTIPTEXT;
  935. info.hdr.hwndFrom = GetSafeHwnd();
  936. info.hdr.idFrom = GetDlgCtrlID();
  937. info.lItem = nItem;
  938. //plus 100 for extra info - shortcut and such
  939. int maxCharacters = CGetSetOptions::GetMaxToolTipCharacters();
  940. info.cchTextMax = min(maxCharacters, g_Opt.m_bDescTextSize) + 200;
  941. info.pszText = csText.GetBufferSetLength(info.cchTextMax);
  942. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  943. csText.ReleaseBuffer();
  944. }
  945. }
  946. BOOL CQListCtrl::GetClipData(int nItem, CClipFormat &Clip)
  947. {
  948. return theApp.GetClipData(GetItemData(nItem), Clip);
  949. }
  950. DWORD CQListCtrl::GetItemData(int nItem)
  951. {
  952. if ((GetStyle() & LVS_OWNERDATA))
  953. {
  954. CWnd* pParent = GetParent();
  955. if (pParent && (pParent->GetSafeHwnd() != NULL))
  956. {
  957. LV_DISPINFO info;
  958. memset(&info, 0, sizeof(info));
  959. info.hdr.code = LVN_GETDISPINFO;
  960. info.hdr.hwndFrom = GetSafeHwnd();
  961. info.hdr.idFrom = GetDlgCtrlID();
  962. info.item.iItem = nItem;
  963. info.item.lParam = -1;
  964. info.item.mask = LVIF_PARAM;
  965. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  966. return (DWORD)info.item.lParam;
  967. }
  968. }
  969. return (DWORD)CListCtrl::GetItemData(nItem);
  970. }
  971. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_DIB_ClipFormat(int nItem)
  972. {
  973. CClipFormatQListCtrl *format = NULL;
  974. CWnd* pParent = GetParent();
  975. if (pParent && (pParent->GetSafeHwnd() != NULL))
  976. {
  977. LV_DISPINFO info;
  978. memset(&info, 0, sizeof(info));
  979. info.hdr.code = LVN_GETDISPINFO;
  980. info.hdr.hwndFrom = GetSafeHwnd();
  981. info.hdr.idFrom = GetDlgCtrlID();
  982. info.item.iItem = nItem;
  983. info.item.lParam = NULL;
  984. info.item.mask = LVIF_CF_DIB;
  985. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  986. if (info.item.lParam != NULL)
  987. {
  988. format = (CClipFormatQListCtrl *)info.item.lParam;
  989. }
  990. }
  991. return format;
  992. }
  993. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_RTF_ClipFormat(int nItem)
  994. {
  995. CClipFormatQListCtrl *format = NULL;
  996. CWnd* pParent = GetParent();
  997. if (pParent && (pParent->GetSafeHwnd() != NULL))
  998. {
  999. LV_DISPINFO info;
  1000. memset(&info, 0, sizeof(info));
  1001. info.hdr.code = LVN_GETDISPINFO;
  1002. info.hdr.hwndFrom = GetSafeHwnd();
  1003. info.hdr.idFrom = GetDlgCtrlID();
  1004. info.item.iItem = nItem;
  1005. info.item.lParam = NULL;
  1006. info.item.mask = LVIF_CF_RICHTEXT;
  1007. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  1008. if (info.item.lParam != NULL)
  1009. {
  1010. format = (CClipFormatQListCtrl *)info.item.lParam;
  1011. }
  1012. }
  1013. return format;
  1014. }
  1015. void CQListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1016. {
  1017. CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
  1018. }
  1019. void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate, CppSQLite3DB &db)
  1020. {
  1021. m_Accels.RemoveAll();
  1022. if (bCreate)
  1023. {
  1024. CMainTableFunctions::LoadAcceleratorKeys(m_Accels, db);
  1025. LoadDittoCopyBufferHotkeys();
  1026. }
  1027. }
  1028. void CQListCtrl::LoadDittoCopyBufferHotkeys()
  1029. {
  1030. CCopyBufferItem Item;
  1031. CAccel a;
  1032. g_Opt.GetCopyBufferItem(0, Item);
  1033. if (Item.m_lCopyHotKey > 0)
  1034. {
  1035. a.Cmd = COPY_BUFFER_HOT_KEY_1_ID;
  1036. a.Key = Item.m_lCopyHotKey;
  1037. m_Accels.AddAccel(a);
  1038. }
  1039. g_Opt.GetCopyBufferItem(1, Item);
  1040. if (Item.m_lCopyHotKey > 0)
  1041. {
  1042. a.Cmd = COPY_BUFFER_HOT_KEY_2_ID;
  1043. a.Key = Item.m_lCopyHotKey;
  1044. m_Accels.AddAccel(a);
  1045. }
  1046. g_Opt.GetCopyBufferItem(2, Item);
  1047. if (Item.m_lCopyHotKey > 0)
  1048. {
  1049. a.Cmd = COPY_BUFFER_HOT_KEY_3_ID;
  1050. a.Key = Item.m_lCopyHotKey;
  1051. m_Accels.AddAccel(a);
  1052. }
  1053. }
  1054. void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
  1055. {
  1056. CListCtrl::OnKillFocus(pNewWnd);
  1057. //if(FocusOnToolTip() == FALSE)
  1058. //m_pToolTip->Hide();
  1059. }
  1060. HWND CQListCtrl::GetToolTipHWnd()
  1061. {
  1062. if (VALID_TOOLTIP)
  1063. return m_pToolTip->GetSafeHwnd();
  1064. return NULL;
  1065. }
  1066. BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = 0 */)
  1067. {
  1068. return CListCtrl::SetItemCountEx(iCount, dwFlags);
  1069. }
  1070. void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
  1071. {
  1072. NMLISTVIEW *pnmv = (NMLISTVIEW *)pNMHDR;
  1073. if ((pnmv->uNewState == 3) ||
  1074. (pnmv->uNewState == 1))
  1075. {
  1076. if (VALID_TOOLTIP &&
  1077. ::IsWindowVisible(m_pToolTip->m_hWnd))
  1078. {
  1079. this->ShowFullDescription(false, true);
  1080. }
  1081. if (g_Opt.m_bAllwaysShowDescription)
  1082. {
  1083. KillTimer(TIMER_SHOW_PROPERTIES);
  1084. SetTimer(TIMER_SHOW_PROPERTIES, 300, NULL);
  1085. }
  1086. if (GetSelectedCount() > 0)
  1087. theApp.SetStatus(NULL, FALSE);
  1088. }
  1089. if (GetSelectedCount() == this->GetItemCount())
  1090. {
  1091. if (m_allSelected == false)
  1092. {
  1093. Log(StrF(_T("List box Select All")));
  1094. GetParent()->SendMessage(NM_ALL_SELECTED, 0, 0);
  1095. m_allSelected = true;
  1096. }
  1097. }
  1098. else if (m_allSelected == true)
  1099. {
  1100. Log(StrF(_T("List box REMOVED Select All")));
  1101. m_allSelected = false;
  1102. }
  1103. }
  1104. void CQListCtrl::OnTimer(UINT_PTR nIDEvent)
  1105. {
  1106. //http://support.microsoft.com/kb/200054
  1107. //OnTimer() Is Not Called Repeatedly for a List Control
  1108. bool callBase = true;
  1109. switch (nIDEvent)
  1110. {
  1111. case TIMER_SHOW_PROPERTIES:
  1112. {
  1113. if (theApp.m_bShowingQuickPaste)
  1114. ShowFullDescription(true);
  1115. KillTimer(TIMER_SHOW_PROPERTIES);
  1116. callBase = false;
  1117. }
  1118. break;
  1119. case TIMER_HIDE_SCROL:
  1120. {
  1121. CPoint cursorPos;
  1122. GetCursorPos(&cursorPos);
  1123. CRect crWindow;
  1124. this->GetWindowRect(&crWindow);
  1125. //check and see if they moved out of the scroll area
  1126. //If they did tell our parent so
  1127. if (MouseInScrollBarArea(crWindow, cursorPos) == false)
  1128. {
  1129. StopHideScrollBarTimer();
  1130. }
  1131. callBase = false;
  1132. }
  1133. break;
  1134. case TIMER_SHOW_SCROLL:
  1135. {
  1136. CPoint cursorPos;
  1137. GetCursorPos(&cursorPos);
  1138. CRect crWindow;
  1139. this->GetWindowRect(&crWindow);
  1140. //Adjust for the v-scroll bar being off of the screen
  1141. crWindow.right -= m_windowDpi->Scale(GetSystemMetrics(SM_CXVSCROLL));
  1142. crWindow.bottom -= m_windowDpi->Scale(::GetSystemMetrics(SM_CXHSCROLL));
  1143. //Check and see if we are still in the cursor area
  1144. if (MouseInScrollBarArea(crWindow, cursorPos))
  1145. {
  1146. m_timerToHideScrollAreaSet = true;
  1147. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);
  1148. //Start looking to hide the scroll bars
  1149. SetTimer(TIMER_HIDE_SCROL, 1000, NULL);
  1150. }
  1151. KillTimer(TIMER_SHOW_SCROLL);
  1152. callBase = false;
  1153. }
  1154. break;
  1155. }
  1156. if (callBase)
  1157. {
  1158. CListCtrl::OnTimer(nIDEvent);
  1159. }
  1160. }
  1161. void CQListCtrl::SetLogFont(LOGFONT &font)
  1162. {
  1163. m_Font.DeleteObject();
  1164. m_boldFont.DeleteObject();
  1165. m_Font.CreateFontIndirect(&font);
  1166. font.lfWeight = 600;
  1167. m_boldFont.CreateFontIndirect(&font);
  1168. SetFont(&m_Font);
  1169. }
  1170. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1171. {
  1172. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  1173. }
  1174. BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  1175. {
  1176. NMLVCACHEHINT* pcachehint = NULL;
  1177. if (message == WM_NOTIFY)
  1178. {
  1179. NMHDR* phdr = (NMHDR*)lParam;
  1180. switch (phdr->code)
  1181. {
  1182. case LVN_ODCACHEHINT:
  1183. pcachehint = (NMLVCACHEHINT*)phdr;
  1184. GetParent()->SendMessage(NM_FILL_REST_OF_LIST, pcachehint->iFrom, pcachehint->iTo);
  1185. return FALSE;
  1186. }
  1187. }
  1188. return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
  1189. }
  1190. BOOL CQListCtrl::OnItemDeleted(long lID)
  1191. {
  1192. BOOL bRet2 = m_RTFData.RemoveKey(lID);
  1193. return (bRet2);
  1194. }
  1195. void CQListCtrl::OnMouseMove(UINT nFlags, CPoint point)
  1196. {
  1197. if (g_Opt.m_showScrollBar == FALSE)
  1198. {
  1199. CPoint cursorPos;
  1200. GetCursorPos(&cursorPos);
  1201. CRect crWindow;
  1202. this->GetWindowRect(&crWindow);
  1203. ScreenToClient(&crWindow);
  1204. crWindow.right -= m_windowDpi->Scale(::GetSystemMetrics(SM_CXVSCROLL));
  1205. crWindow.bottom -= m_windowDpi->Scale(::GetSystemMetrics(SM_CXHSCROLL));
  1206. if (MouseInScrollBarArea(crWindow, point))
  1207. {
  1208. if ((GetTickCount() - m_mouseOverScrollAreaStart) > 500)
  1209. {
  1210. SetTimer(TIMER_SHOW_SCROLL, 500, NULL);
  1211. m_mouseOverScrollAreaStart = GetTickCount();
  1212. }
  1213. }
  1214. else
  1215. {
  1216. if (m_timerToHideScrollAreaSet)
  1217. {
  1218. StopHideScrollBarTimer();
  1219. }
  1220. KillTimer(TIMER_SHOW_SCROLL);
  1221. }
  1222. }
  1223. CListCtrl::OnMouseMove(nFlags, point);
  1224. }
  1225. bool CQListCtrl::MouseInScrollBarArea(CRect crWindow, CPoint point)
  1226. {
  1227. CRect crRight(crWindow);
  1228. CRect crBottom(crWindow);
  1229. crRight.left = crRight.right - m_windowDpi->Scale(::GetSystemMetrics(SM_CXVSCROLL));
  1230. crBottom.top = crBottom.bottom - m_windowDpi->Scale(::GetSystemMetrics(SM_CYHSCROLL));
  1231. /*CString cs;
  1232. cs.Format(_T("point.x: %d, Width: %d, Height: %d\n"), point.x, crWindow.Width(), crWindow.Height());
  1233. OutputDebugString(cs);*/
  1234. if (crRight.PtInRect(point) || crBottom.PtInRect(point))
  1235. {
  1236. return true;
  1237. }
  1238. return false;
  1239. }
  1240. void CQListCtrl::StopHideScrollBarTimer()
  1241. {
  1242. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
  1243. m_timerToHideScrollAreaSet = false;
  1244. KillTimer(TIMER_HIDE_SCROL);
  1245. }
  1246. void CQListCtrl::SetSearchText(CString text)
  1247. {
  1248. m_searchText = text;
  1249. }
  1250. void CQListCtrl::HidePopup(bool checkShowPersistant)
  1251. {
  1252. if (VALID_TOOLTIP)
  1253. {
  1254. if (checkShowPersistant == false ||
  1255. m_pToolTip->GetShowPersistant() == false)
  1256. {
  1257. m_pToolTip->Hide();
  1258. }
  1259. }
  1260. }
  1261. BOOL CQListCtrl::IsToolTipWindowVisible()
  1262. {
  1263. if (VALID_TOOLTIP)
  1264. {
  1265. return ::IsWindowVisible(m_toolTipHwnd);
  1266. }
  1267. return FALSE;
  1268. }
  1269. void CQListCtrl::ToggleToolTipShowPersistant()
  1270. {
  1271. if (VALID_TOOLTIP)
  1272. {
  1273. m_pToolTip->ToggleShowPersistant();
  1274. }
  1275. }
  1276. bool CQListCtrl::ToggleToolTipWordWrap()
  1277. {
  1278. bool didWordWrap = false;
  1279. if (VALID_TOOLTIP)
  1280. {
  1281. didWordWrap = m_pToolTip->ToggleWordWrap();
  1282. }
  1283. return didWordWrap;
  1284. }
  1285. BOOL CQListCtrl::IsToolTipWindowFocus()
  1286. {
  1287. if (VALID_TOOLTIP)
  1288. {
  1289. return ::GetFocus() == m_toolTipHwnd ||
  1290. ::GetParent(::GetFocus()) == m_toolTipHwnd;
  1291. }
  1292. return FALSE;
  1293. }
  1294. bool CQListCtrl::IsToolTipShowPersistant()
  1295. {
  1296. if (VALID_TOOLTIP)
  1297. {
  1298. return m_pToolTip->GetShowPersistant();
  1299. }
  1300. return false;
  1301. }
  1302. void CQListCtrl::DoToolTipSearch()
  1303. {
  1304. if (VALID_TOOLTIP)
  1305. {
  1306. return m_pToolTip->DoSearch();
  1307. }
  1308. }
  1309. void CQListCtrl::HideToolTip()
  1310. {
  1311. if (VALID_TOOLTIP)
  1312. {
  1313. m_pToolTip->Hide();
  1314. }
  1315. }
  1316. void CQListCtrl::OnDpiChanged()
  1317. {
  1318. SetDpiInfo(m_windowDpi);
  1319. }
  1320. void CQListCtrl::SetDpiInfo(CDPI *dpi)
  1321. {
  1322. m_windowDpi = dpi;
  1323. m_groupFolder.Reset();
  1324. 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"));
  1325. m_dontDeleteImage.Reset();
  1326. 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"));
  1327. m_inFolderImage.Reset();
  1328. 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"));
  1329. m_shortCutImage.Reset();
  1330. 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"));
  1331. m_stickyImage.Reset();
  1332. 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"));
  1333. DeleteObject(m_SmallFont);
  1334. CreateSmallFont();
  1335. }
  1336. void CQListCtrl::CreateSmallFont()
  1337. {
  1338. LOGFONT lf;
  1339. lf.lfHeight = -MulDiv(g_Opt.GetFirstTenHotKeysFontSize(), m_windowDpi->GetDPI(), 72);
  1340. lf.lfWidth = 0;
  1341. lf.lfEscapement = 0;
  1342. lf.lfOrientation = 0;
  1343. lf.lfWeight = FW_LIGHT;
  1344. lf.lfItalic = FALSE;
  1345. lf.lfUnderline = FALSE;
  1346. lf.lfStrikeOut = FALSE;
  1347. lf.lfCharSet = ANSI_CHARSET;
  1348. lf.lfOutPrecision = OUT_STRING_PRECIS;
  1349. lf.lfClipPrecision = CLIP_STROKE_PRECIS;
  1350. lf.lfQuality = DEFAULT_QUALITY;
  1351. lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE;
  1352. lstrcpy(lf.lfFaceName, _T("Small Font"));
  1353. m_SmallFont = ::CreateFontIndirect(&lf);
  1354. }
  1355. void CQListCtrl::OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt)
  1356. {
  1357. if (zDelta < 0)
  1358. {
  1359. this->SendMessage(WM_HSCROLL, SB_LINERIGHT, NULL);
  1360. }
  1361. else
  1362. {
  1363. this->SendMessage(WM_HSCROLL, SB_LINELEFT, NULL);
  1364. }
  1365. //CListCtrl::OnMouseHWheel(nFlags, zDelta, pt);
  1366. }