QListCtrl.cpp 40 KB

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