QListCtrl.cpp 38 KB

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