QListCtrl.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662
  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. char *pData = (char*)GlobalLock(pThumbnail->m_hgData);
  437. if (pData)
  438. {
  439. //somehow ms word places crazy rtf text onto the clipboard and our draw routine doesn't handle that
  440. //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
  441. m_rtfFormater.SetRTF((char*)pData);
  442. CString betterRTF = m_rtfFormater.GetRTF();
  443. CComBSTR bStr(betterRTF);
  444. m_pFormatter->put_RTFText(bStr);
  445. m_pFormatter->Draw(pDC->m_hDC, crRect);
  446. bRet = TRUE;
  447. }
  448. }
  449. return bRet;
  450. }
  451. // DrawBitMap loads a DIB from the DB, draws a crRect thumbnail of the image
  452. // to pDC and caches that thumbnail as a DIB in m_ThumbNails[ ItemID ].
  453. // ALL items are cached in m_ThumbNails (those without images are cached with NULL m_hgData)
  454. BOOL CQListCtrl::DrawBitMap(int nItem, CRect &crRect, CDC *pDC, const CString &csDescription)
  455. {
  456. if (g_Opt.m_bDrawThumbnail == FALSE)
  457. return FALSE;
  458. CClipFormatQListCtrl *format = GetItem_CF_DIB_ClipFormat(nItem);
  459. if (format != NULL)
  460. {
  461. HGLOBAL smallImage = format->GetDibFittingToHeight(pDC, crRect.Height());
  462. if (smallImage != NULL)
  463. {
  464. //Will return the width of the bitmap in nWidth
  465. int nWidth = 0;
  466. if (CBitmapHelper::DrawDIB(pDC, smallImage, crRect.left, crRect.top, nWidth))
  467. {
  468. // adjust the rect so other information can be drawn next to the thumbnail
  469. crRect.left += nWidth + 3;
  470. }
  471. }
  472. }
  473. else if (csDescription.Find(_T("CF_DIB")) == 0)
  474. {
  475. crRect.left += crRect.Height();
  476. }
  477. return TRUE;
  478. }
  479. void CQListCtrl::RefreshVisibleRows()
  480. {
  481. int nTopIndex = GetTopIndex();
  482. int nLastIndex = nTopIndex + GetCountPerPage();
  483. RedrawItems(nTopIndex, nLastIndex);
  484. }
  485. void CQListCtrl::RefreshRow(int row)
  486. {
  487. RedrawItems(row, row);
  488. }
  489. void CQListCtrl::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  490. {
  491. CListCtrl::OnSysKeyDown(nChar, nRepCnt, nFlags);
  492. }
  493. BOOL CQListCtrl::OnEraseBkgnd(CDC* pDC)
  494. {
  495. CRect rect;
  496. GetClientRect(&rect);
  497. CBrush myBrush(g_Opt.m_Theme.MainWindowBG()); // dialog background color
  498. CBrush *pOld = pDC->SelectObject(&myBrush);
  499. BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
  500. pDC->SelectObject(pOld); // restore old brush
  501. return bRes; // CDialog::OnEraseBkgnd(pDC);
  502. // Simply returning TRUE seems OK since we do custom item
  503. // painting. However, there is a pixel buffer around the
  504. // border of this control (not within the item rects)
  505. // which becomes visually corrupt if it is not erased.
  506. // In most cases, I do not notice the erasure, so I have kept
  507. // the call to CListCtrl::OnEraseBkgnd(pDC);
  508. // However, for some reason, bulk erasure is very noticeable when
  509. // shift-scrolling the page to select a block of items, so
  510. // I made a special case for that:
  511. //if(GetSelectedCount() >= 2)
  512. // return TRUE;
  513. //return CListCtrl::OnEraseBkgnd(pDC);
  514. }
  515. BOOL CQListCtrl::OnToolTipText(UINT id, NMHDR * pNMHDR, LRESULT * pResult)
  516. {
  517. // need to handle both ANSI and UNICODE versions of the message
  518. TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
  519. TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
  520. CString strTipText;
  521. UINT_PTR nID = pNMHDR->idFrom;
  522. if (nID == 0) // Notification in NT from automatically
  523. return FALSE; // created tooltip
  524. ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 500);
  525. if (g_Opt.m_tooltipTimeout > 0)
  526. {
  527. ::SendMessage(pNMHDR->hwndFrom, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELPARAM(g_Opt.m_tooltipTimeout, 0));
  528. }
  529. // Use Item's name as the tool tip. Change this for something different.
  530. // Like use its file size, etc.
  531. GetToolTipText((int)nID - 1, strTipText);
  532. //Replace the tabs with spaces, the tooltip didn't like the \t s
  533. strTipText.Replace(_T("\t"), _T(" "));
  534. int nLength = strTipText.GetLength() + 2;
  535. #ifndef _UNICODE
  536. if (pNMHDR->code == TTN_NEEDTEXTA)
  537. {
  538. if (m_pchTip != NULL)
  539. delete m_pchTip;
  540. m_pchTip = new TCHAR[nLength];
  541. lstrcpyn(m_pchTip, strTipText, nLength - 1);
  542. m_pchTip[nLength - 1] = 0;
  543. pTTTW->lpszText = (WCHAR*)m_pchTip;
  544. }
  545. else
  546. {
  547. if (m_pwchTip != NULL)
  548. delete m_pwchTip;
  549. m_pwchTip = new WCHAR[nLength];
  550. _mbstowcsz(m_pwchTip, strTipText, nLength - 1);
  551. m_pwchTip[nLength - 1] = 0; // end of text
  552. pTTTW->lpszText = (WCHAR*)m_pwchTip;
  553. }
  554. #else
  555. if (pNMHDR->code == TTN_NEEDTEXTA)
  556. {
  557. if (m_pchTip != NULL)
  558. delete m_pchTip;
  559. m_pchTip = new TCHAR[nLength];
  560. STRNCPY(m_pchTip, strTipText, nLength - 1);
  561. m_pchTip[nLength - 1] = 0; // end of text
  562. pTTTW->lpszText = (LPTSTR)m_pchTip;
  563. }
  564. else
  565. {
  566. if (m_pwchTip != NULL)
  567. delete m_pwchTip;
  568. m_pwchTip = new WCHAR[nLength];
  569. lstrcpyn(m_pwchTip, strTipText, nLength - 1);
  570. m_pwchTip[nLength - 1] = 0;
  571. pTTTW->lpszText = (LPTSTR)m_pwchTip;
  572. }
  573. #endif
  574. *pResult = 0;
  575. return TRUE; // message was handled
  576. }
  577. INT_PTR CQListCtrl::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
  578. {
  579. CRect rect;
  580. GetClientRect(&rect);
  581. if (rect.PtInRect(point))
  582. {
  583. if (GetItemCount())
  584. {
  585. int nTopIndex = GetTopIndex();
  586. int nBottomIndex = nTopIndex + GetCountPerPage();
  587. if (nBottomIndex > GetItemCount()) nBottomIndex = GetItemCount();
  588. for (int nIndex = nTopIndex; nIndex <= nBottomIndex; nIndex++)
  589. {
  590. GetItemRect(nIndex, rect, LVIR_BOUNDS);
  591. if (rect.PtInRect(point))
  592. {
  593. pTI->hwnd = m_hWnd;
  594. pTI->uId = (UINT)(nIndex + 1);
  595. pTI->lpszText = LPSTR_TEXTCALLBACK;
  596. pTI->rect = rect;
  597. pTI->uFlags = TTF_TRANSPARENT;
  598. return pTI->uId;
  599. }
  600. }
  601. }
  602. }
  603. return -1;
  604. }
  605. int CQListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  606. {
  607. if (CListCtrl::OnCreate(lpCreateStruct) == -1)
  608. return -1;
  609. if (g_Opt.m_tooltipTimeout > 0 ||
  610. g_Opt.m_tooltipTimeout == -1)
  611. {
  612. EnableToolTips();
  613. }
  614. else
  615. {
  616. EnableToolTips(FALSE);
  617. }
  618. //m_pToolTip = new CToolTipEx;
  619. //m_pToolTip->Create(this);
  620. //m_pToolTip->SetNotifyWnd(GetParent());
  621. return 0;
  622. }
  623. BOOL CQListCtrl::PreTranslateMessage(MSG* pMsg)
  624. {
  625. CAccel a;
  626. if (m_Accels.OnMsg(pMsg, a))
  627. {
  628. switch (a.Cmd)
  629. {
  630. case COPY_BUFFER_HOT_KEY_1_ID:
  631. PutSelectedItemOnDittoCopyBuffer(0);
  632. break;
  633. case COPY_BUFFER_HOT_KEY_2_ID:
  634. PutSelectedItemOnDittoCopyBuffer(1);
  635. break;
  636. case COPY_BUFFER_HOT_KEY_3_ID:
  637. PutSelectedItemOnDittoCopyBuffer(2);
  638. break;
  639. default:
  640. if (a.RefId == CHotKey::PASTE_OPEN_CLIP)
  641. {
  642. GetParent()->SendMessage(NM_SELECT_DB_ID, a.Cmd, 0);
  643. }
  644. else if (a.RefId == CHotKey::MOVE_TO_GROUP)
  645. {
  646. GetParent()->SendMessage(NM_MOVE_TO_GROUP, a.Cmd, 0);
  647. }
  648. }
  649. return TRUE;
  650. }
  651. if (VALID_TOOLTIP)
  652. {
  653. if (m_pToolTip->OnMsg(pMsg))
  654. return TRUE;
  655. }
  656. switch (pMsg->message)
  657. {
  658. case WM_KEYDOWN:
  659. if (HandleKeyDown(pMsg->wParam, pMsg->lParam))
  660. return TRUE;
  661. break; // end case WM_KEYDOWN
  662. case WM_MOUSEWHEEL:
  663. break;
  664. case WM_VSCROLL:
  665. ASSERT(FALSE);
  666. break;
  667. } // end switch(pMsg->message)
  668. return CListCtrl::PreTranslateMessage(pMsg);
  669. }
  670. BOOL CQListCtrl::HandleKeyDown(WPARAM wParam, LPARAM lParam)
  671. {
  672. if (VALID_TOOLTIP)
  673. {
  674. MSG Msg;
  675. Msg.lParam = lParam;
  676. Msg.wParam = wParam;
  677. Msg.message = WM_KEYDOWN;
  678. if (m_pToolTip->OnMsg(&Msg))
  679. return TRUE;
  680. }
  681. WPARAM vk = wParam;
  682. switch (vk)
  683. {
  684. case 'A': // Ctrl-A = Select All
  685. if (CONTROL_PRESSED)
  686. {
  687. int nCount = GetItemCount();
  688. for (int i = 0; i < nCount; i++)
  689. {
  690. SetSelection(i);
  691. }
  692. return TRUE;
  693. }
  694. break;
  695. case VK_HOME:
  696. SetListPos(0);
  697. break;
  698. } // end switch(vk)
  699. return FALSE;
  700. }
  701. bool CQListCtrl::PostEventLoadedCheckDescription(int updatedRow)
  702. {
  703. bool loadedClip = false;
  704. if (VALID_TOOLTIP)
  705. {
  706. int toolTipClipId = m_pToolTip->GetClipId();
  707. int toolTipClipRow = m_pToolTip->GetClipRow();
  708. if (toolTipClipRow >= 0)
  709. {
  710. log(StrF(_T("PostEventLoadedCheckDescription refreshRow: %d tt_row: %d tt_id: %d"), updatedRow, toolTipClipRow, toolTipClipId));
  711. }
  712. //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
  713. //see if we need to show this rows description
  714. if (toolTipClipId <= 0 &&
  715. toolTipClipRow == updatedRow &&
  716. ::IsWindow(m_toolTipHwnd))
  717. {
  718. ShowFullDescription(false, true);
  719. loadedClip = true;
  720. }
  721. }
  722. return loadedClip;
  723. }
  724. bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
  725. {
  726. if (this->GetSelectedCount() == 0)
  727. {
  728. return false;
  729. }
  730. int clipRow = this->GetCaret();
  731. int clipId = this->GetItemData(clipRow);
  732. log(StrF(_T("Show full description row: %d id: %d"), clipRow, clipId));
  733. if (VALID_TOOLTIP &&
  734. clipId > 0 &&
  735. m_pToolTip->GetClipId() == clipId &&
  736. ::IsWindow(m_toolTipHwnd))
  737. {
  738. return false;
  739. }
  740. int nItem = GetCaret();
  741. CRect rc, crWindow;
  742. GetWindowRect(&crWindow);
  743. GetItemRect(nItem, rc, LVIR_BOUNDS);
  744. ClientToScreen(rc);
  745. CPoint pt;
  746. if (CGetSetOptions::GetRememberDescPos())
  747. {
  748. CGetSetOptions::GetDescWndPoint(pt);
  749. }
  750. else if (bFromAuto == false)
  751. {
  752. pt = CPoint(rc.left, rc.bottom);
  753. }
  754. else
  755. {
  756. pt = CPoint((crWindow.left + (crWindow.right - crWindow.left) / 2), rc.bottom);
  757. }
  758. CString csDescription;
  759. GetToolTipText(nItem, csDescription);
  760. if (m_pToolTip == NULL ||
  761. fromNextPrev == false ||
  762. ::IsWindow(m_toolTipHwnd) == FALSE)
  763. {
  764. if (m_pToolTip != NULL)
  765. {
  766. m_pToolTip->DestroyWindow();
  767. }
  768. m_pToolTip = new CToolTipEx;
  769. m_pToolTip->Create(this);
  770. m_toolTipHwnd = m_pToolTip->GetSafeHwnd();
  771. m_pToolTip->SetNotifyWnd(GetParent());
  772. }
  773. else if (VALID_TOOLTIP)
  774. {
  775. CRect r;
  776. m_pToolTip->GetWindowRectEx(r);
  777. pt = r.TopLeft();
  778. m_pToolTip->SetGdiplusBitmap(NULL);
  779. m_pToolTip->SetRTFText("");
  780. m_pToolTip->SetToolTipText(_T(""));
  781. m_pToolTip->SetFolderPath(_T(""));
  782. }
  783. if (VALID_TOOLTIP)
  784. {
  785. m_pToolTip->SetTooltipActions(m_pToolTipActions);
  786. m_pToolTip->SetClipId(clipId);
  787. m_pToolTip->SetClipRow(clipRow);
  788. m_pToolTip->SetSearchText(m_searchText);
  789. LOGFONT lf;
  790. m_Font.GetLogFont(&lf);
  791. lf.lfHeight = m_windowDpi->UnScale(lf.lfHeight);
  792. m_pToolTip->SetLogFont(&lf, FALSE);
  793. m_pToolTip->SetClipData(_T(""));
  794. m_pToolTip->SetToolTipText(_T(""));
  795. m_pToolTip->SetRTFText(" ");
  796. bool bSetPlainText = false;
  797. CClipFormat Clip;
  798. try
  799. {
  800. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, lDate, lastPasteDate, lDontAutoDelete, QuickPasteText, lShortCut, globalShortCut, stickyClipOrder, stickyClipGroupOrder, lParentID FROM Main WHERE lID = %d"), clipId);
  801. if (q.eof() == false)
  802. {
  803. CString clipData;
  804. COleDateTime time((time_t)q.getIntField(_T("lDate")));
  805. clipData += "Added: " + time.Format();
  806. COleDateTime modified((time_t)q.getIntField(_T("lastPasteDate")));
  807. clipData += _T(" | Last Used: ") + modified.Format();
  808. if (q.getIntField(_T("lDontAutoDelete")) > 0)
  809. {
  810. clipData += _T(" | Never Auto Delete");
  811. }
  812. CString csQuickPaste = q.getStringField(_T("QuickPasteText"));
  813. if (csQuickPaste.IsEmpty() == FALSE)
  814. {
  815. clipData += _T(" | Quick Paste = ");
  816. clipData += csQuickPaste;
  817. }
  818. int shortCut = q.getIntField(_T("lShortCut"));
  819. if (shortCut > 0)
  820. {
  821. clipData += _T(" | ");
  822. clipData += CHotKey::GetHotKeyDisplayStatic(shortCut);
  823. BOOL globalShortCut = q.getIntField(_T("globalShortCut"));
  824. if (globalShortCut)
  825. {
  826. clipData += _T(" - Global Shortcut Key");
  827. }
  828. }
  829. if (theApp.m_GroupID > 0)
  830. {
  831. int sticky = q.getIntField(_T("stickyClipGroupOrder"));
  832. if (sticky != INVALID_STICKY)
  833. {
  834. clipData += _T(" | ");
  835. clipData += _T(" - Sticky In Group");
  836. }
  837. }
  838. else
  839. {
  840. int sticky = q.getIntField(_T("stickyClipOrder"));
  841. if (sticky != INVALID_STICKY)
  842. {
  843. clipData += _T(" | ");
  844. clipData += _T(" - Sticky");
  845. }
  846. }
  847. int parentId = q.getIntField(_T("lParentID"));
  848. if (parentId > 0)
  849. {
  850. CString folder = FolderPath(parentId);
  851. m_pToolTip->SetFolderPath(folder);
  852. }
  853. m_pToolTip->SetClipData(clipData);
  854. }
  855. }
  856. CATCH_SQLITE_EXCEPTION
  857. Clip.m_cfType = CF_UNICODETEXT;
  858. if (GetClipData(nItem, Clip) && Clip.m_hgData)
  859. {
  860. LPVOID pvData = GlobalLock(Clip.m_hgData);
  861. if (pvData)
  862. {
  863. CString csText = (WCHAR*)pvData;
  864. m_pToolTip->SetToolTipText(csText);
  865. bSetPlainText = true;
  866. }
  867. GlobalUnlock(Clip.m_hgData);
  868. Clip.Free();
  869. Clip.Clear();
  870. }
  871. if (bSetPlainText == false)
  872. {
  873. Clip.m_cfType = CF_TEXT;
  874. if (GetClipData(nItem, Clip) && Clip.m_hgData)
  875. {
  876. LPVOID pvData = GlobalLock(Clip.m_hgData);
  877. if (pvData)
  878. {
  879. CString csText = (char*)pvData;
  880. m_pToolTip->SetToolTipText(csText);
  881. bSetPlainText = true;
  882. }
  883. GlobalUnlock(Clip.m_hgData);
  884. Clip.Free();
  885. Clip.Clear();
  886. }
  887. }
  888. if (bSetPlainText == false)
  889. {
  890. m_pToolTip->SetToolTipText(csDescription);
  891. }
  892. Clip.m_cfType = RegisterClipboardFormat(CF_RTF);
  893. if (GetClipData(nItem, Clip) && Clip.m_hgData)
  894. {
  895. LPVOID pvData = GlobalLock(Clip.m_hgData);
  896. if (pvData)
  897. {
  898. m_pToolTip->SetRTFText((char*)pvData);
  899. }
  900. GlobalUnlock(Clip.m_hgData);
  901. Clip.Free();
  902. Clip.Clear();
  903. }
  904. m_pToolTip->SetHtmlText(_T(""));
  905. Clip.m_cfType = GetFormatID(_T("HTML Format"));
  906. if (GetClipData(nItem, Clip) && Clip.m_hgData)
  907. {
  908. LPVOID pvData = GlobalLock(Clip.m_hgData);
  909. if (pvData)
  910. {
  911. CString html;
  912. CTextConvert::ConvertFromUTF8(CStringA((char*)pvData), html);
  913. m_pToolTip->SetHtmlText(html);
  914. }
  915. GlobalUnlock(Clip.m_hgData);
  916. Clip.Free();
  917. Clip.Clear();
  918. }
  919. Clip.m_cfType = CF_DIB;
  920. if (GetClipData(nItem, Clip) && Clip.m_hgData)
  921. {
  922. m_pToolTip->SetGdiplusBitmap(Clip.CreateGdiplusBitmap());
  923. }
  924. else
  925. {
  926. Clip.m_cfType = theApp.m_PNG_Format;
  927. if (GetClipData(nItem, Clip) && Clip.m_hgData)
  928. {
  929. m_pToolTip->SetGdiplusBitmap(Clip.CreateGdiplusBitmap());
  930. }
  931. }
  932. m_pToolTip->Show(pt);
  933. }
  934. return true;
  935. }
  936. void CQListCtrl::GetToolTipText(int nItem, CString &csText)
  937. {
  938. CWnd* pParent = GetParent();
  939. if (pParent && (pParent->GetSafeHwnd() != NULL))
  940. {
  941. CQListToolTipText info;
  942. memset(&info, 0, sizeof(info));
  943. info.hdr.code = NM_GETTOOLTIPTEXT;
  944. info.hdr.hwndFrom = GetSafeHwnd();
  945. info.hdr.idFrom = GetDlgCtrlID();
  946. info.lItem = nItem;
  947. //plus 100 for extra info - shortcut and such
  948. int maxCharacters = CGetSetOptions::GetMaxToolTipCharacters();
  949. info.cchTextMax = min(maxCharacters, g_Opt.m_bDescTextSize) + 200;
  950. info.pszText = csText.GetBufferSetLength(info.cchTextMax);
  951. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  952. csText.ReleaseBuffer();
  953. }
  954. }
  955. BOOL CQListCtrl::GetClipData(int nItem, CClipFormat &Clip)
  956. {
  957. return theApp.GetClipData(GetItemData(nItem), Clip);
  958. }
  959. DWORD CQListCtrl::GetItemData(int nItem)
  960. {
  961. if ((GetStyle() & LVS_OWNERDATA))
  962. {
  963. CWnd* pParent = GetParent();
  964. if (pParent && (pParent->GetSafeHwnd() != NULL))
  965. {
  966. LV_DISPINFO info;
  967. memset(&info, 0, sizeof(info));
  968. info.hdr.code = LVN_GETDISPINFO;
  969. info.hdr.hwndFrom = GetSafeHwnd();
  970. info.hdr.idFrom = GetDlgCtrlID();
  971. info.item.iItem = nItem;
  972. info.item.lParam = -1;
  973. info.item.mask = LVIF_PARAM;
  974. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  975. return (DWORD)info.item.lParam;
  976. }
  977. }
  978. return (DWORD)CListCtrl::GetItemData(nItem);
  979. }
  980. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_DIB_ClipFormat(int nItem)
  981. {
  982. CClipFormatQListCtrl *format = NULL;
  983. CWnd* pParent = GetParent();
  984. if (pParent && (pParent->GetSafeHwnd() != NULL))
  985. {
  986. LV_DISPINFO info;
  987. memset(&info, 0, sizeof(info));
  988. info.hdr.code = LVN_GETDISPINFO;
  989. info.hdr.hwndFrom = GetSafeHwnd();
  990. info.hdr.idFrom = GetDlgCtrlID();
  991. info.item.iItem = nItem;
  992. info.item.lParam = NULL;
  993. info.item.mask = LVIF_CF_DIB;
  994. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  995. if (info.item.lParam != NULL)
  996. {
  997. format = (CClipFormatQListCtrl *)info.item.lParam;
  998. }
  999. }
  1000. return format;
  1001. }
  1002. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_RTF_ClipFormat(int nItem)
  1003. {
  1004. CClipFormatQListCtrl *format = NULL;
  1005. CWnd* pParent = GetParent();
  1006. if (pParent && (pParent->GetSafeHwnd() != NULL))
  1007. {
  1008. LV_DISPINFO info;
  1009. memset(&info, 0, sizeof(info));
  1010. info.hdr.code = LVN_GETDISPINFO;
  1011. info.hdr.hwndFrom = GetSafeHwnd();
  1012. info.hdr.idFrom = GetDlgCtrlID();
  1013. info.item.iItem = nItem;
  1014. info.item.lParam = NULL;
  1015. info.item.mask = LVIF_CF_RICHTEXT;
  1016. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  1017. if (info.item.lParam != NULL)
  1018. {
  1019. format = (CClipFormatQListCtrl *)info.item.lParam;
  1020. }
  1021. }
  1022. return format;
  1023. }
  1024. void CQListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1025. {
  1026. CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
  1027. }
  1028. void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate, CppSQLite3DB &db)
  1029. {
  1030. m_Accels.RemoveAll();
  1031. if (bCreate)
  1032. {
  1033. CMainTableFunctions::LoadAcceleratorKeys(m_Accels, db);
  1034. LoadDittoCopyBufferHotkeys();
  1035. }
  1036. }
  1037. void CQListCtrl::LoadDittoCopyBufferHotkeys()
  1038. {
  1039. CCopyBufferItem Item;
  1040. CAccel a;
  1041. g_Opt.GetCopyBufferItem(0, Item);
  1042. if (Item.m_lCopyHotKey > 0)
  1043. {
  1044. a.Cmd = COPY_BUFFER_HOT_KEY_1_ID;
  1045. a.Key = Item.m_lCopyHotKey;
  1046. m_Accels.AddAccel(a);
  1047. }
  1048. g_Opt.GetCopyBufferItem(1, Item);
  1049. if (Item.m_lCopyHotKey > 0)
  1050. {
  1051. a.Cmd = COPY_BUFFER_HOT_KEY_2_ID;
  1052. a.Key = Item.m_lCopyHotKey;
  1053. m_Accels.AddAccel(a);
  1054. }
  1055. g_Opt.GetCopyBufferItem(2, Item);
  1056. if (Item.m_lCopyHotKey > 0)
  1057. {
  1058. a.Cmd = COPY_BUFFER_HOT_KEY_3_ID;
  1059. a.Key = Item.m_lCopyHotKey;
  1060. m_Accels.AddAccel(a);
  1061. }
  1062. }
  1063. void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
  1064. {
  1065. CListCtrl::OnKillFocus(pNewWnd);
  1066. //if(FocusOnToolTip() == FALSE)
  1067. //m_pToolTip->Hide();
  1068. }
  1069. HWND CQListCtrl::GetToolTipHWnd()
  1070. {
  1071. if (VALID_TOOLTIP)
  1072. return m_pToolTip->GetSafeHwnd();
  1073. return NULL;
  1074. }
  1075. BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = 0 */)
  1076. {
  1077. return CListCtrl::SetItemCountEx(iCount, dwFlags);
  1078. }
  1079. void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
  1080. {
  1081. NMLISTVIEW *pnmv = (NMLISTVIEW *)pNMHDR;
  1082. if ((pnmv->uNewState == 3) ||
  1083. (pnmv->uNewState == 1))
  1084. {
  1085. if (VALID_TOOLTIP &&
  1086. ::IsWindowVisible(m_pToolTip->m_hWnd))
  1087. {
  1088. this->ShowFullDescription(false, true);
  1089. }
  1090. if (g_Opt.m_bAllwaysShowDescription)
  1091. {
  1092. KillTimer(TIMER_SHOW_PROPERTIES);
  1093. SetTimer(TIMER_SHOW_PROPERTIES, 300, NULL);
  1094. }
  1095. if (GetSelectedCount() > 0)
  1096. theApp.SetStatus(NULL, FALSE);
  1097. }
  1098. if (GetSelectedCount() == this->GetItemCount())
  1099. {
  1100. if (m_allSelected == false)
  1101. {
  1102. Log(StrF(_T("List box Select All")));
  1103. GetParent()->SendMessage(NM_ALL_SELECTED, 0, 0);
  1104. m_allSelected = true;
  1105. }
  1106. }
  1107. else if (m_allSelected == true)
  1108. {
  1109. Log(StrF(_T("List box REMOVED Select All")));
  1110. m_allSelected = false;
  1111. }
  1112. }
  1113. void CQListCtrl::OnTimer(UINT_PTR nIDEvent)
  1114. {
  1115. //http://support.microsoft.com/kb/200054
  1116. //OnTimer() Is Not Called Repeatedly for a List Control
  1117. bool callBase = true;
  1118. switch (nIDEvent)
  1119. {
  1120. case TIMER_SHOW_PROPERTIES:
  1121. {
  1122. if (theApp.m_bShowingQuickPaste)
  1123. ShowFullDescription(true);
  1124. KillTimer(TIMER_SHOW_PROPERTIES);
  1125. callBase = false;
  1126. }
  1127. break;
  1128. case TIMER_HIDE_SCROL:
  1129. {
  1130. CPoint cursorPos;
  1131. GetCursorPos(&cursorPos);
  1132. CRect crWindow;
  1133. this->GetWindowRect(&crWindow);
  1134. //check and see if they moved out of the scroll area
  1135. //If they did tell our parent so
  1136. if (MouseInScrollBarArea(crWindow, cursorPos) == false)
  1137. {
  1138. StopHideScrollBarTimer();
  1139. }
  1140. callBase = false;
  1141. }
  1142. break;
  1143. case TIMER_SHOW_SCROLL:
  1144. {
  1145. CPoint cursorPos;
  1146. GetCursorPos(&cursorPos);
  1147. CRect crWindow;
  1148. this->GetWindowRect(&crWindow);
  1149. //Adjust for the v-scroll bar being off of the screen
  1150. crWindow.right -= m_windowDpi->Scale(GetSystemMetrics(SM_CXVSCROLL));
  1151. crWindow.bottom -= m_windowDpi->Scale(::GetSystemMetrics(SM_CXHSCROLL));
  1152. //Check and see if we are still in the cursor area
  1153. if (MouseInScrollBarArea(crWindow, cursorPos))
  1154. {
  1155. m_timerToHideScrollAreaSet = true;
  1156. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);
  1157. //Start looking to hide the scroll bars
  1158. SetTimer(TIMER_HIDE_SCROL, 1000, NULL);
  1159. }
  1160. KillTimer(TIMER_SHOW_SCROLL);
  1161. callBase = false;
  1162. }
  1163. break;
  1164. }
  1165. if (callBase)
  1166. {
  1167. CListCtrl::OnTimer(nIDEvent);
  1168. }
  1169. }
  1170. void CQListCtrl::SetLogFont(LOGFONT &font)
  1171. {
  1172. m_Font.DeleteObject();
  1173. m_boldFont.DeleteObject();
  1174. m_Font.CreateFontIndirect(&font);
  1175. font.lfWeight = 600;
  1176. m_boldFont.CreateFontIndirect(&font);
  1177. SetFont(&m_Font);
  1178. }
  1179. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1180. {
  1181. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  1182. }
  1183. BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  1184. {
  1185. NMLVCACHEHINT* pcachehint = NULL;
  1186. if (message == WM_NOTIFY)
  1187. {
  1188. NMHDR* phdr = (NMHDR*)lParam;
  1189. switch (phdr->code)
  1190. {
  1191. case LVN_ODCACHEHINT:
  1192. pcachehint = (NMLVCACHEHINT*)phdr;
  1193. GetParent()->SendMessage(NM_FILL_REST_OF_LIST, pcachehint->iFrom, pcachehint->iTo);
  1194. return FALSE;
  1195. }
  1196. }
  1197. return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
  1198. }
  1199. BOOL CQListCtrl::OnItemDeleted(long lID)
  1200. {
  1201. BOOL bRet2 = m_RTFData.RemoveKey(lID);
  1202. return (bRet2);
  1203. }
  1204. void CQListCtrl::OnMouseMove(UINT nFlags, CPoint point)
  1205. {
  1206. if (g_Opt.m_showScrollBar == FALSE)
  1207. {
  1208. CPoint cursorPos;
  1209. GetCursorPos(&cursorPos);
  1210. CRect crWindow;
  1211. this->GetWindowRect(&crWindow);
  1212. ScreenToClient(&crWindow);
  1213. crWindow.right -= m_windowDpi->Scale(::GetSystemMetrics(SM_CXVSCROLL));
  1214. crWindow.bottom -= m_windowDpi->Scale(::GetSystemMetrics(SM_CXHSCROLL));
  1215. if (MouseInScrollBarArea(crWindow, point))
  1216. {
  1217. if ((GetTickCount() - m_mouseOverScrollAreaStart) > 500)
  1218. {
  1219. SetTimer(TIMER_SHOW_SCROLL, 500, NULL);
  1220. m_mouseOverScrollAreaStart = GetTickCount();
  1221. }
  1222. }
  1223. else
  1224. {
  1225. if (m_timerToHideScrollAreaSet)
  1226. {
  1227. StopHideScrollBarTimer();
  1228. }
  1229. KillTimer(TIMER_SHOW_SCROLL);
  1230. }
  1231. }
  1232. CListCtrl::OnMouseMove(nFlags, point);
  1233. }
  1234. bool CQListCtrl::MouseInScrollBarArea(CRect crWindow, CPoint point)
  1235. {
  1236. CRect crRight(crWindow);
  1237. CRect crBottom(crWindow);
  1238. crRight.left = crRight.right - m_windowDpi->Scale(::GetSystemMetrics(SM_CXVSCROLL));
  1239. crBottom.top = crBottom.bottom - m_windowDpi->Scale(::GetSystemMetrics(SM_CYHSCROLL));
  1240. /*CString cs;
  1241. cs.Format(_T("point.x: %d, Width: %d, Height: %d\n"), point.x, crWindow.Width(), crWindow.Height());
  1242. OutputDebugString(cs);*/
  1243. if (crRight.PtInRect(point) || crBottom.PtInRect(point))
  1244. {
  1245. return true;
  1246. }
  1247. return false;
  1248. }
  1249. void CQListCtrl::StopHideScrollBarTimer()
  1250. {
  1251. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
  1252. m_timerToHideScrollAreaSet = false;
  1253. KillTimer(TIMER_HIDE_SCROL);
  1254. }
  1255. void CQListCtrl::SetSearchText(CString text)
  1256. {
  1257. m_searchText = text;
  1258. }
  1259. void CQListCtrl::HidePopup(bool checkShowPersistant)
  1260. {
  1261. if (VALID_TOOLTIP)
  1262. {
  1263. if (checkShowPersistant == false ||
  1264. m_pToolTip->GetShowPersistant() == false)
  1265. {
  1266. m_pToolTip->Hide();
  1267. }
  1268. }
  1269. }
  1270. BOOL CQListCtrl::IsToolTipWindowVisible()
  1271. {
  1272. if (VALID_TOOLTIP)
  1273. {
  1274. return ::IsWindowVisible(m_toolTipHwnd);
  1275. }
  1276. return FALSE;
  1277. }
  1278. void CQListCtrl::ToggleToolTipShowPersistant()
  1279. {
  1280. if (VALID_TOOLTIP)
  1281. {
  1282. m_pToolTip->ToggleShowPersistant();
  1283. }
  1284. }
  1285. bool CQListCtrl::ToggleToolTipWordWrap()
  1286. {
  1287. bool didWordWrap = false;
  1288. if (VALID_TOOLTIP)
  1289. {
  1290. didWordWrap = m_pToolTip->ToggleWordWrap();
  1291. }
  1292. return didWordWrap;
  1293. }
  1294. BOOL CQListCtrl::IsToolTipWindowFocus()
  1295. {
  1296. if (VALID_TOOLTIP)
  1297. {
  1298. return ::GetFocus() == m_toolTipHwnd ||
  1299. ::GetParent(::GetFocus()) == m_toolTipHwnd;
  1300. }
  1301. return FALSE;
  1302. }
  1303. bool CQListCtrl::IsToolTipShowPersistant()
  1304. {
  1305. if (VALID_TOOLTIP)
  1306. {
  1307. return m_pToolTip->GetShowPersistant();
  1308. }
  1309. return false;
  1310. }
  1311. void CQListCtrl::DoToolTipSearch()
  1312. {
  1313. if (VALID_TOOLTIP)
  1314. {
  1315. return m_pToolTip->DoSearch();
  1316. }
  1317. }
  1318. void CQListCtrl::HideToolTip()
  1319. {
  1320. if (VALID_TOOLTIP)
  1321. {
  1322. m_pToolTip->Hide();
  1323. }
  1324. }
  1325. void CQListCtrl::OnDpiChanged()
  1326. {
  1327. SetDpiInfo(m_windowDpi);
  1328. }
  1329. void CQListCtrl::SetDpiInfo(CDPI *dpi)
  1330. {
  1331. m_windowDpi = dpi;
  1332. m_groupFolder.Reset();
  1333. 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"));
  1334. m_dontDeleteImage.Reset();
  1335. 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"));
  1336. m_inFolderImage.Reset();
  1337. 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"));
  1338. m_shortCutImage.Reset();
  1339. 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"));
  1340. m_stickyImage.Reset();
  1341. 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"));
  1342. DeleteObject(m_SmallFont);
  1343. CreateSmallFont();
  1344. }
  1345. void CQListCtrl::CreateSmallFont()
  1346. {
  1347. LOGFONT lf;
  1348. lf.lfHeight = -MulDiv(g_Opt.GetFirstTenHotKeysFontSize(), m_windowDpi->GetDPI(), 72);
  1349. lf.lfWidth = 0;
  1350. lf.lfEscapement = 0;
  1351. lf.lfOrientation = 0;
  1352. lf.lfWeight = FW_LIGHT;
  1353. lf.lfItalic = FALSE;
  1354. lf.lfUnderline = FALSE;
  1355. lf.lfStrikeOut = FALSE;
  1356. lf.lfCharSet = ANSI_CHARSET;
  1357. lf.lfOutPrecision = OUT_STRING_PRECIS;
  1358. lf.lfClipPrecision = CLIP_STROKE_PRECIS;
  1359. lf.lfQuality = DEFAULT_QUALITY;
  1360. lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE;
  1361. lstrcpy(lf.lfFaceName, _T("Small Font"));
  1362. m_SmallFont = ::CreateFontIndirect(&lf);
  1363. }
  1364. void CQListCtrl::OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt)
  1365. {
  1366. if (zDelta < 0)
  1367. {
  1368. this->SendMessage(WM_HSCROLL, SB_LINERIGHT, NULL);
  1369. }
  1370. else
  1371. {
  1372. this->SendMessage(WM_HSCROLL, SB_LINELEFT, NULL);
  1373. }
  1374. //CListCtrl::OnMouseHWheel(nFlags, zDelta, pt);
  1375. }