QListCtrl.cpp 41 KB

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