QListCtrl.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567
  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 &&
  367. strSymbols.Find(_T("<group>")) < 0 &&
  368. strSymbols.Find(_T("<sticky>")) < 0) //don't auto delete
  369. {
  370. m_dontDeleteImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  371. rcText.left += m_dontDeleteImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  372. }
  373. if (strSymbols.Find(_T("<shortcut>")) >= 0) // has shortcut
  374. {
  375. m_shortCutImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  376. rcText.left += m_shortCutImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  377. }
  378. if (drawInGroupIcon &&
  379. strSymbols.Find(_T("<ingroup>")) >= 0) // in group
  380. {
  381. m_inFolderImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  382. rcText.left += m_inFolderImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  383. }
  384. if (strSymbols.Find(_T("<qpastetext>")) >= 0) // has quick paste text
  385. {
  386. }
  387. if (strSymbols.Find(_T("<sticky>")) >= 0) //sticky clip
  388. {
  389. m_stickyImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  390. rcText.left += m_stickyImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  391. }
  392. }
  393. if(DrawRtfText(nItem, rcText, pDC) == FALSE)
  394. {
  395. //use unprintable characters so it doesn't find copied html to convert
  396. if (m_searchText.GetLength() > 0 &&
  397. FindNoCaseAndInsert(csText, m_searchText, _T("\x01\x04 color='#ff0000'\x02"), _T("\x01\x03\x04\x02"), m_linesPerRow) > 0)
  398. {
  399. DrawHTML(pDC->m_hDC, csText, csText.GetLength(), rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
  400. }
  401. else
  402. {
  403. pDC->DrawText(csText, rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
  404. }
  405. }
  406. // Draw a focus rect around the item if necessary.
  407. //if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
  408. // pDC->DrawFocusRect(rcItem);
  409. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  410. {
  411. CString cs;
  412. if( firstTenNum == 10 )
  413. cs = "0";
  414. else
  415. cs.Format(_T("%d"), firstTenNum);
  416. CRect crClient;
  417. GetWindowRect(crClient);
  418. ScreenToClient(crClient);
  419. CRect crHotKey = rcItem;
  420. int extraFromClipWasPaste = 0;
  421. if (m_showIfClipWasPasted)
  422. extraFromClipWasPaste = 3;
  423. crHotKey.right = crHotKey.left + theApp.m_metrics.ScaleX(11);
  424. crHotKey.left += theApp.m_metrics.ScaleX(1 + extraFromClipWasPaste);
  425. crHotKey.top += theApp.m_metrics.ScaleX(1 + extraFromClipWasPaste);
  426. HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
  427. COLORREF localOldTextColor = pDC->SetTextColor(g_Opt.m_Theme.ListSmallQuickPasteIndexColor());
  428. CPen pen(PS_SOLID, 0, g_Opt.m_Theme.ListSmallQuickPasteIndexColor());
  429. CPen* pOldPen = pDC->SelectObject(&pen);
  430. pDC->DrawText(cs, crHotKey, DT_BOTTOM);
  431. pDC->MoveTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(8 + extraFromClipWasPaste), rcItem.top));
  432. pDC->LineTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(8 + extraFromClipWasPaste), rcItem.bottom));
  433. pDC->SelectObject(hOldFont);
  434. pDC->SetTextColor(localOldTextColor);
  435. pDC->SelectObject(pOldPen);
  436. }
  437. // restore the previous values
  438. if(OldColor > -1)
  439. pDC->SetTextColor(OldColor);
  440. if(nOldBKMode > -1)
  441. pDC->SetBkMode(nOldBKMode);
  442. *pResult = CDRF_SKIPDEFAULT; // We've painted everything.
  443. }
  444. }
  445. BOOL CQListCtrl::DrawRtfText(int nItem, CRect &crRect, CDC *pDC)
  446. {
  447. if(g_Opt.m_bDrawRTF == FALSE)
  448. return FALSE;
  449. BOOL bRet = FALSE;
  450. CClipFormat* pThumbnail = GetItem_CF_RTF_ClipFormat(nItem);
  451. if(pThumbnail == NULL)
  452. return FALSE;
  453. // if there's no data, then we're done.
  454. if(pThumbnail->m_hgData == NULL)
  455. return FALSE;
  456. if(m_pFormatter == NULL)
  457. {
  458. m_pFormatter = new CFormattedTextDraw;
  459. m_pFormatter->Create();
  460. }
  461. if(m_pFormatter)
  462. {
  463. char *pData = (char*)GlobalLock(pThumbnail->m_hgData);
  464. if(pData)
  465. {
  466. CComBSTR bStr(pData);
  467. m_pFormatter->put_RTFText(bStr);
  468. m_pFormatter->Draw(pDC->m_hDC, crRect);
  469. GlobalUnlock(pThumbnail->m_hgData);
  470. bRet = TRUE;
  471. }
  472. }
  473. return bRet;
  474. }
  475. // DrawBitMap loads a DIB from the DB, draws a crRect thumbnail of the image
  476. // to pDC and caches that thumbnail as a DIB in m_ThumbNails[ ItemID ].
  477. // ALL items are cached in m_ThumbNails (those without images are cached with NULL m_hgData)
  478. BOOL CQListCtrl::DrawBitMap(int nItem, CRect &crRect, CDC *pDC, const CString &csDescription)
  479. {
  480. if(g_Opt.m_bDrawThumbnail == FALSE)
  481. return FALSE;
  482. CClipFormatQListCtrl *format = GetItem_CF_DIB_ClipFormat(nItem);
  483. if(format != NULL)
  484. {
  485. HGLOBAL smallImage = format->GetDib(pDC, crRect.Height());
  486. if(smallImage != NULL)
  487. {
  488. //Will return the width of the bitmap in nWidth
  489. int nWidth = 0;
  490. if(CBitmapHelper::DrawDIB(pDC, smallImage, crRect.left, crRect.top, nWidth))
  491. {
  492. // adjust the rect so other information can be drawn next to the thumbnail
  493. crRect.left += nWidth + 3;
  494. }
  495. }
  496. }
  497. else if(csDescription.Find(_T("CF_DIB")) == 0)
  498. {
  499. crRect.left += crRect.Height();
  500. }
  501. return TRUE;
  502. }
  503. void CQListCtrl::RefreshVisibleRows()
  504. {
  505. int nTopIndex = GetTopIndex();
  506. int nLastIndex = nTopIndex + GetCountPerPage();
  507. RedrawItems(nTopIndex, nLastIndex);
  508. }
  509. void CQListCtrl::RefreshRow(int row)
  510. {
  511. RedrawItems(row, row);
  512. }
  513. void CQListCtrl::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  514. {
  515. CListCtrl::OnSysKeyDown(nChar, nRepCnt, nFlags);
  516. }
  517. BOOL CQListCtrl::OnEraseBkgnd(CDC* pDC)
  518. {
  519. CRect rect;
  520. GetClientRect(&rect);
  521. CBrush myBrush(g_Opt.m_Theme.MainWindowBG()); // dialog background color
  522. CBrush *pOld = pDC->SelectObject(&myBrush);
  523. BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
  524. pDC->SelectObject(pOld); // restore old brush
  525. return bRes; // CDialog::OnEraseBkgnd(pDC);
  526. // Simply returning TRUE seems OK since we do custom item
  527. // painting. However, there is a pixel buffer around the
  528. // border of this control (not within the item rects)
  529. // which becomes visually corrupt if it is not erased.
  530. // In most cases, I do not notice the erasure, so I have kept
  531. // the call to CListCtrl::OnEraseBkgnd(pDC);
  532. // However, for some reason, bulk erasure is very noticeable when
  533. // shift-scrolling the page to select a block of items, so
  534. // I made a special case for that:
  535. //if(GetSelectedCount() >= 2)
  536. // return TRUE;
  537. //return CListCtrl::OnEraseBkgnd(pDC);
  538. }
  539. BOOL CQListCtrl::OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  540. {
  541. // need to handle both ANSI and UNICODE versions of the message
  542. TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
  543. TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
  544. CString strTipText;
  545. UINT_PTR nID = pNMHDR->idFrom;
  546. if(nID == 0) // Notification in NT from automatically
  547. return FALSE; // created tooltip
  548. ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 500);
  549. // Use Item's name as the tool tip. Change this for something different.
  550. // Like use its file size, etc.
  551. GetToolTipText((int)nID-1, strTipText);
  552. //Replace the tabs with spaces, the tooltip didn't like the \t s
  553. strTipText.Replace(_T("\t"), _T(" "));
  554. int nLength = strTipText.GetLength()+2;
  555. #ifndef _UNICODE
  556. if (pNMHDR->code == TTN_NEEDTEXTA)
  557. {
  558. if(m_pchTip != NULL)
  559. delete m_pchTip;
  560. m_pchTip = new TCHAR[nLength];
  561. lstrcpyn(m_pchTip, strTipText, nLength-1);
  562. m_pchTip[nLength-1] = 0;
  563. pTTTW->lpszText = (WCHAR*)m_pchTip;
  564. }
  565. else
  566. {
  567. if(m_pwchTip != NULL)
  568. delete m_pwchTip;
  569. m_pwchTip = new WCHAR[nLength];
  570. _mbstowcsz(m_pwchTip, strTipText, nLength-1);
  571. m_pwchTip[nLength-1] = 0; // end of text
  572. pTTTW->lpszText = (WCHAR*)m_pwchTip;
  573. }
  574. #else
  575. if(pNMHDR->code == TTN_NEEDTEXTA)
  576. {
  577. if(m_pchTip != NULL)
  578. delete m_pchTip;
  579. m_pchTip = new TCHAR[nLength];
  580. STRNCPY(m_pchTip, strTipText, nLength-1);
  581. m_pchTip[nLength-1] = 0; // end of text
  582. pTTTW->lpszText = (LPTSTR)m_pchTip;
  583. }
  584. else
  585. {
  586. if(m_pwchTip != NULL)
  587. delete m_pwchTip;
  588. m_pwchTip = new WCHAR[nLength];
  589. lstrcpyn(m_pwchTip, strTipText, nLength-1);
  590. m_pwchTip[nLength-1] = 0;
  591. pTTTW->lpszText = (LPTSTR) m_pwchTip;
  592. }
  593. #endif
  594. *pResult = 0;
  595. return TRUE; // message was handled
  596. }
  597. INT_PTR CQListCtrl::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
  598. {
  599. CRect rect;
  600. GetClientRect(&rect);
  601. if(rect.PtInRect(point))
  602. {
  603. if(GetItemCount())
  604. {
  605. int nTopIndex = GetTopIndex();
  606. int nBottomIndex = nTopIndex + GetCountPerPage();
  607. if(nBottomIndex > GetItemCount()) nBottomIndex = GetItemCount();
  608. for(int nIndex = nTopIndex; nIndex <= nBottomIndex; nIndex++)
  609. {
  610. GetItemRect(nIndex, rect, LVIR_BOUNDS);
  611. if(rect.PtInRect(point))
  612. {
  613. pTI->hwnd = m_hWnd;
  614. pTI->uId = (UINT)(nIndex+1);
  615. pTI->lpszText = LPSTR_TEXTCALLBACK;
  616. pTI->rect = rect;
  617. pTI->uFlags = TTF_TRANSPARENT;
  618. return pTI->uId;
  619. }
  620. }
  621. }
  622. }
  623. return -1;
  624. }
  625. int CQListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  626. {
  627. if (CListCtrl::OnCreate(lpCreateStruct) == -1)
  628. return -1;
  629. EnableToolTips();
  630. m_pToolTip = new CToolTipEx;
  631. m_pToolTip->Create(this);
  632. m_pToolTip->SetNotifyWnd(GetParent());
  633. return 0;
  634. }
  635. BOOL CQListCtrl::PreTranslateMessage(MSG* pMsg)
  636. {
  637. CAccel a;
  638. if(m_Accels.OnMsg(pMsg, a))
  639. {
  640. switch(a.Cmd)
  641. {
  642. case COPY_BUFFER_HOT_KEY_1_ID:
  643. PutSelectedItemOnDittoCopyBuffer(0);
  644. break;
  645. case COPY_BUFFER_HOT_KEY_2_ID:
  646. PutSelectedItemOnDittoCopyBuffer(1);
  647. break;
  648. case COPY_BUFFER_HOT_KEY_3_ID:
  649. PutSelectedItemOnDittoCopyBuffer(2);
  650. break;
  651. default:
  652. if(a.RefId == CHotKey::PASTE_OPEN_CLIP)
  653. {
  654. GetParent()->SendMessage(NM_SELECT_DB_ID, a.Cmd, 0);
  655. }
  656. else if(a.RefId == CHotKey::MOVE_TO_GROUP)
  657. {
  658. GetParent()->SendMessage(NM_MOVE_TO_GROUP, a.Cmd, 0);
  659. }
  660. }
  661. return TRUE;
  662. }
  663. if(VALID_TOOLTIP)
  664. {
  665. if(m_pToolTip->OnMsg(pMsg))
  666. return TRUE;
  667. }
  668. switch(pMsg->message)
  669. {
  670. case WM_KEYDOWN:
  671. if(HandleKeyDown(pMsg->wParam, pMsg->lParam))
  672. return TRUE;
  673. break; // end case WM_KEYDOWN
  674. case WM_VSCROLL:
  675. ASSERT(FALSE);
  676. break;
  677. } // end switch(pMsg->message)
  678. return CListCtrl::PreTranslateMessage(pMsg);
  679. }
  680. BOOL CQListCtrl::HandleKeyDown(WPARAM wParam, LPARAM lParam)
  681. {
  682. if(VALID_TOOLTIP)
  683. {
  684. MSG Msg;
  685. Msg.lParam = lParam;
  686. Msg.wParam = wParam;
  687. Msg.message = WM_KEYDOWN;
  688. if(m_pToolTip->OnMsg(&Msg))
  689. return TRUE;
  690. }
  691. WPARAM vk = wParam;
  692. switch( vk )
  693. {
  694. case 'X': // Ctrl-X = Cut (prepare for moving the items into a Group)
  695. if(CONTROL_PRESSED)
  696. {
  697. LoadCopyOrCutToClipboard();
  698. theApp.IC_Cut(); // uses selection
  699. return TRUE;
  700. }
  701. break;
  702. case 'C': // Ctrl-C = Copy (prepare for copying the items into a Group)
  703. if(CONTROL_PRESSED)
  704. {
  705. LoadCopyOrCutToClipboard();
  706. theApp.IC_Copy(); // uses selection
  707. return TRUE;
  708. }
  709. break;
  710. case 'V': // Ctrl-V = Paste (actually performs the copy or move of items into the current Group)
  711. if(CONTROL_PRESSED)
  712. {
  713. theApp.IC_Paste();
  714. return TRUE;
  715. }
  716. break;
  717. case 'A': // Ctrl-A = Select All
  718. if(CONTROL_PRESSED)
  719. {
  720. int nCount = GetItemCount();
  721. for(int i = 0; i < nCount; i++)
  722. {
  723. SetSelection(i);
  724. }
  725. return TRUE;
  726. }
  727. break;
  728. case VK_HOME:
  729. SetListPos(0);
  730. break;
  731. } // end switch(vk)
  732. return FALSE;
  733. }
  734. void CQListCtrl::LoadCopyOrCutToClipboard()
  735. {
  736. ARRAY arr;
  737. GetSelectionItemData(arr);
  738. INT_PTR count = arr.GetSize();
  739. if(count <= 0)
  740. return;
  741. CProcessPaste paste;
  742. //Don't send the paste just load it into memory
  743. paste.m_bSendPaste = false;
  744. if(count > 1)
  745. paste.GetClipIDs().Copy(arr);
  746. else
  747. paste.GetClipIDs().Add(arr[0]);
  748. //Don't move these to the top
  749. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  750. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  751. paste.DoPaste();
  752. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  753. }
  754. bool CQListCtrl::PostEventLoadedCheckDescription(int updatedRow)
  755. {
  756. bool loadedClip = false;
  757. if (VALID_TOOLTIP)
  758. {
  759. int toolTipClipId = m_pToolTip->GetClipId();
  760. int toolTipClipRow = m_pToolTip->GetClipRow();
  761. if (toolTipClipRow >= 0)
  762. {
  763. log(StrF(_T("PostEventLoadedCheckDescription refreshRow: %d tt_row: %d tt_id: %d"), updatedRow, toolTipClipRow, toolTipClipId));
  764. }
  765. //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
  766. //see if we need to show this rows description
  767. if (toolTipClipId <= 0 &&
  768. toolTipClipRow == updatedRow &&
  769. ::IsWindow(m_toolTipHwnd))
  770. {
  771. ShowFullDescription(false, true);
  772. loadedClip = true;
  773. }
  774. }
  775. return loadedClip;
  776. }
  777. bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
  778. {
  779. if (this->GetSelectedCount() == 0)
  780. {
  781. return false;
  782. }
  783. int clipRow = this->GetCaret();
  784. int clipId = this->GetItemData(clipRow);
  785. log(StrF(_T("Show full description row: %d id: %d"), clipRow, clipId));
  786. if(VALID_TOOLTIP &&
  787. clipId > 0 &&
  788. m_pToolTip->GetClipId() == clipId &&
  789. ::IsWindow(m_toolTipHwnd))
  790. {
  791. return false;
  792. }
  793. int nItem = GetCaret();
  794. CRect rc, crWindow;
  795. GetWindowRect(&crWindow);
  796. GetItemRect(nItem, rc, LVIR_BOUNDS);
  797. ClientToScreen(rc);
  798. CPoint pt;
  799. if(CGetSetOptions::GetRememberDescPos())
  800. {
  801. CGetSetOptions::GetDescWndPoint(pt);
  802. }
  803. else if(bFromAuto == false)
  804. {
  805. pt = CPoint(rc.left, rc.bottom);
  806. }
  807. else
  808. {
  809. pt = CPoint((crWindow.left + (crWindow.right - crWindow.left)/2), rc.bottom);
  810. }
  811. CString csDescription;
  812. GetToolTipText(nItem, csDescription);
  813. if (m_pToolTip == NULL ||
  814. fromNextPrev == false ||
  815. ::IsWindow(m_toolTipHwnd) == FALSE)
  816. {
  817. m_pToolTip->DestroyWindow();
  818. m_pToolTip = new CToolTipEx;
  819. m_pToolTip->Create(this);
  820. m_toolTipHwnd = m_pToolTip->GetSafeHwnd();
  821. m_pToolTip->SetNotifyWnd(GetParent());
  822. }
  823. else if(VALID_TOOLTIP)
  824. {
  825. CRect r;
  826. m_pToolTip->GetWindowRect(r);
  827. pt = r.TopLeft();
  828. m_pToolTip->SetBitmap(NULL);
  829. m_pToolTip->SetRTFText("");
  830. m_pToolTip->SetToolTipText(_T(""));
  831. }
  832. if(VALID_TOOLTIP)
  833. {
  834. m_pToolTip->SetClipId(clipId);
  835. m_pToolTip->SetClipRow(clipRow);
  836. m_pToolTip->SetSearchText(m_searchText);
  837. m_pToolTip->SetClipData(_T(""));
  838. m_pToolTip->SetToolTipText(_T(""));
  839. m_pToolTip->SetRTFText(" ");
  840. bool bSetPlainText = false;
  841. CClipFormat Clip;
  842. try
  843. {
  844. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, lDate, lastPasteDate, lDontAutoDelete, QuickPasteText, lShortCut, globalShortCut FROM Main WHERE lID = %d"), clipId);
  845. if (q.eof() == false)
  846. {
  847. CString clipData;
  848. COleDateTime time((time_t)q.getIntField(_T("lDate")));
  849. clipData += "Added: " + time.Format();
  850. COleDateTime modified((time_t)q.getIntField(_T("lastPasteDate")));
  851. clipData += _T(" | Last Used: ") + modified.Format();
  852. if (q.getIntField(_T("lDontAutoDelete")) > 0)
  853. {
  854. clipData += _T(" | Never Auto Delete");
  855. }
  856. CString csQuickPaste = q.getStringField(_T("QuickPasteText"));
  857. if (csQuickPaste.IsEmpty() == FALSE)
  858. {
  859. clipData += _T(" | Quick Paste = ");
  860. clipData += csQuickPaste;
  861. }
  862. int shortCut = q.getIntField(_T("lShortCut"));
  863. if (shortCut > 0)
  864. {
  865. clipData += _T(" | ");
  866. clipData += CHotKey::GetHotKeyDisplayStatic(shortCut);
  867. BOOL globalShortCut = q.getIntField(_T("globalShortCut"));
  868. if (globalShortCut)
  869. {
  870. clipData += _T(" - Global Shortcut Key");
  871. }
  872. }
  873. m_pToolTip->SetClipData(clipData);
  874. }
  875. }
  876. CATCH_SQLITE_EXCEPTION
  877. Clip.m_cfType = CF_UNICODETEXT;
  878. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  879. {
  880. LPVOID pvData = GlobalLock(Clip.m_hgData);
  881. if(pvData)
  882. {
  883. CString csText = (WCHAR*)pvData;
  884. m_pToolTip->SetToolTipText(csText);
  885. bSetPlainText = true;
  886. }
  887. GlobalUnlock(Clip.m_hgData);
  888. Clip.Free();
  889. Clip.Clear();
  890. }
  891. if(bSetPlainText == false)
  892. {
  893. Clip.m_cfType = CF_TEXT;
  894. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  895. {
  896. LPVOID pvData = GlobalLock(Clip.m_hgData);
  897. if(pvData)
  898. {
  899. CString csText = (char*)pvData;
  900. m_pToolTip->SetToolTipText(csText);
  901. bSetPlainText = true;
  902. }
  903. GlobalUnlock(Clip.m_hgData);
  904. Clip.Free();
  905. Clip.Clear();
  906. }
  907. }
  908. if(bSetPlainText == false)
  909. {
  910. m_pToolTip->SetToolTipText(csDescription);
  911. }
  912. Clip.m_cfType = RegisterClipboardFormat(CF_RTF);
  913. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  914. {
  915. LPVOID pvData = GlobalLock(Clip.m_hgData);
  916. if(pvData)
  917. {
  918. m_pToolTip->SetRTFText((char*)pvData);
  919. }
  920. GlobalUnlock(Clip.m_hgData);
  921. Clip.Free();
  922. Clip.Clear();
  923. }
  924. Clip.m_cfType = CF_DIB;
  925. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  926. {
  927. CBitmap *pBitMap = new CBitmap;
  928. if(pBitMap)
  929. {
  930. CRect rcItem;
  931. GetWindowRect(rcItem);
  932. CDC *pDC = GetDC();;
  933. CBitmapHelper::GetCBitmap(&Clip, pDC, pBitMap, MAXINT);
  934. ReleaseDC(pDC);
  935. //Tooltip wnd will release
  936. m_pToolTip->SetBitmap(pBitMap);
  937. }
  938. Clip.Free();
  939. Clip.Clear();
  940. }
  941. m_pToolTip->Show(pt);
  942. }
  943. return true;
  944. }
  945. void CQListCtrl::GetToolTipText(int nItem, CString &csText)
  946. {
  947. CWnd* pParent=GetParent();
  948. if(pParent && (pParent->GetSafeHwnd() != NULL))
  949. {
  950. CQListToolTipText info;
  951. memset(&info, 0, sizeof(info));
  952. info.hdr.code = NM_GETTOOLTIPTEXT;
  953. info.hdr.hwndFrom = GetSafeHwnd();
  954. info.hdr.idFrom = GetDlgCtrlID();
  955. info.lItem = nItem;
  956. //plus 100 for extra info - shortcut and such
  957. info.cchTextMax = g_Opt.m_bDescTextSize + 100;
  958. info.pszText = csText.GetBufferSetLength(info.cchTextMax);
  959. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  960. csText.ReleaseBuffer();
  961. }
  962. }
  963. BOOL CQListCtrl::GetClipData(int nItem, CClipFormat &Clip)
  964. {
  965. return theApp.GetClipData(GetItemData(nItem), Clip);
  966. }
  967. DWORD CQListCtrl::GetItemData(int nItem)
  968. {
  969. if((GetStyle() & LVS_OWNERDATA))
  970. {
  971. CWnd* pParent=GetParent();
  972. if(pParent && (pParent->GetSafeHwnd() != NULL))
  973. {
  974. LV_DISPINFO info;
  975. memset(&info, 0, sizeof(info));
  976. info.hdr.code = LVN_GETDISPINFO;
  977. info.hdr.hwndFrom = GetSafeHwnd();
  978. info.hdr.idFrom = GetDlgCtrlID();
  979. info.item.iItem = nItem;
  980. info.item.lParam = -1;
  981. info.item.mask = LVIF_PARAM;
  982. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  983. return (DWORD)info.item.lParam;
  984. }
  985. }
  986. return (DWORD)CListCtrl::GetItemData(nItem);
  987. }
  988. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_DIB_ClipFormat(int nItem)
  989. {
  990. CClipFormatQListCtrl *format = NULL;
  991. CWnd* pParent=GetParent();
  992. if(pParent && (pParent->GetSafeHwnd() != NULL))
  993. {
  994. LV_DISPINFO info;
  995. memset(&info, 0, sizeof(info));
  996. info.hdr.code = LVN_GETDISPINFO;
  997. info.hdr.hwndFrom = GetSafeHwnd();
  998. info.hdr.idFrom = GetDlgCtrlID();
  999. info.item.iItem = nItem;
  1000. info.item.lParam = NULL;
  1001. info.item.mask = LVIF_CF_DIB;
  1002. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  1003. if(info.item.lParam != NULL)
  1004. {
  1005. format = (CClipFormatQListCtrl *)info.item.lParam;
  1006. }
  1007. }
  1008. return format;
  1009. }
  1010. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_RTF_ClipFormat(int nItem)
  1011. {
  1012. CClipFormatQListCtrl *format = NULL;
  1013. CWnd* pParent=GetParent();
  1014. if(pParent && (pParent->GetSafeHwnd() != NULL))
  1015. {
  1016. LV_DISPINFO info;
  1017. memset(&info, 0, sizeof(info));
  1018. info.hdr.code = LVN_GETDISPINFO;
  1019. info.hdr.hwndFrom = GetSafeHwnd();
  1020. info.hdr.idFrom = GetDlgCtrlID();
  1021. info.item.iItem = nItem;
  1022. info.item.lParam = NULL;
  1023. info.item.mask = LVIF_CF_RICHTEXT;
  1024. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  1025. if(info.item.lParam != NULL)
  1026. {
  1027. format = (CClipFormatQListCtrl *)info.item.lParam;
  1028. }
  1029. }
  1030. return format;
  1031. }
  1032. void CQListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1033. {
  1034. CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
  1035. }
  1036. void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate, CppSQLite3DB &db)
  1037. {
  1038. m_Accels.RemoveAll();
  1039. if(bCreate)
  1040. {
  1041. CMainTableFunctions::LoadAcceleratorKeys(m_Accels, db);
  1042. LoadDittoCopyBufferHotkeys();
  1043. }
  1044. }
  1045. void CQListCtrl::LoadDittoCopyBufferHotkeys()
  1046. {
  1047. CCopyBufferItem Item;
  1048. CAccel a;
  1049. g_Opt.GetCopyBufferItem(0, Item);
  1050. if(Item.m_lCopyHotKey > 0)
  1051. {
  1052. a.Cmd = COPY_BUFFER_HOT_KEY_1_ID;
  1053. a.Key = Item.m_lCopyHotKey;
  1054. m_Accels.AddAccel(a);
  1055. }
  1056. g_Opt.GetCopyBufferItem(1, Item);
  1057. if(Item.m_lCopyHotKey > 0)
  1058. {
  1059. a.Cmd = COPY_BUFFER_HOT_KEY_2_ID;
  1060. a.Key = Item.m_lCopyHotKey;
  1061. m_Accels.AddAccel(a);
  1062. }
  1063. g_Opt.GetCopyBufferItem(2, Item);
  1064. if(Item.m_lCopyHotKey > 0)
  1065. {
  1066. a.Cmd = COPY_BUFFER_HOT_KEY_3_ID;
  1067. a.Key = Item.m_lCopyHotKey;
  1068. m_Accels.AddAccel(a);
  1069. }
  1070. }
  1071. void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
  1072. {
  1073. CListCtrl::OnKillFocus(pNewWnd);
  1074. //if(FocusOnToolTip() == FALSE)
  1075. //m_pToolTip->Hide();
  1076. }
  1077. HWND CQListCtrl::GetToolTipHWnd()
  1078. {
  1079. if(VALID_TOOLTIP)
  1080. return m_pToolTip->GetSafeHwnd();
  1081. return NULL;
  1082. }
  1083. BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = 0 */)
  1084. {
  1085. return CListCtrl::SetItemCountEx(iCount, dwFlags);
  1086. }
  1087. void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
  1088. {
  1089. NMLISTVIEW *pnmv = (NMLISTVIEW *) pNMHDR;
  1090. if((pnmv->uNewState == 3) ||
  1091. (pnmv->uNewState == 1))
  1092. {
  1093. if (VALID_TOOLTIP &&
  1094. ::IsWindowVisible(m_pToolTip->m_hWnd))
  1095. {
  1096. this->ShowFullDescription(false, true);
  1097. }
  1098. if(g_Opt.m_bAllwaysShowDescription)
  1099. {
  1100. KillTimer(TIMER_SHOW_PROPERTIES);
  1101. SetTimer(TIMER_SHOW_PROPERTIES, 300, NULL);
  1102. }
  1103. if(GetSelectedCount() > 0 )
  1104. theApp.SetStatus(NULL, FALSE);
  1105. }
  1106. if(GetSelectedCount() == this->GetItemCount())
  1107. {
  1108. if(m_allSelected == false)
  1109. {
  1110. Log(StrF(_T("List box Select All")));
  1111. GetParent()->SendMessage(NM_ALL_SELECTED, 0, 0);
  1112. m_allSelected = true;
  1113. }
  1114. }
  1115. else if(m_allSelected == true)
  1116. {
  1117. Log(StrF(_T("List box REMOVED Select All")));
  1118. m_allSelected = false;
  1119. }
  1120. }
  1121. void CQListCtrl::OnTimer(UINT_PTR nIDEvent)
  1122. {
  1123. //http://support.microsoft.com/kb/200054
  1124. //OnTimer() Is Not Called Repeatedly for a List Control
  1125. bool callBase = true;
  1126. switch(nIDEvent)
  1127. {
  1128. case TIMER_SHOW_PROPERTIES:
  1129. {
  1130. if( theApp.m_bShowingQuickPaste )
  1131. ShowFullDescription(true);
  1132. KillTimer(TIMER_SHOW_PROPERTIES);
  1133. callBase = false;
  1134. }
  1135. break;
  1136. case TIMER_HIDE_SCROL:
  1137. {
  1138. CPoint cursorPos;
  1139. GetCursorPos(&cursorPos);
  1140. CRect crWindow;
  1141. this->GetWindowRect(&crWindow);
  1142. //check and see if they moved out of the scroll area
  1143. //If they did tell our parent so
  1144. if(MouseInScrollBarArea(crWindow, cursorPos) == false)
  1145. {
  1146. StopHideScrollBarTimer();
  1147. }
  1148. callBase = false;
  1149. }
  1150. break;
  1151. case TIMER_SHOW_SCROLL:
  1152. {
  1153. CPoint cursorPos;
  1154. GetCursorPos(&cursorPos);
  1155. CRect crWindow;
  1156. this->GetWindowRect(&crWindow);
  1157. //Adjust for the v-scroll bar being off of the screen
  1158. crWindow.right -= theApp.m_metrics.ScaleX(GetSystemMetrics(SM_CXVSCROLL));
  1159. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1160. //Check and see if we are still in the cursor area
  1161. if(MouseInScrollBarArea(crWindow, cursorPos))
  1162. {
  1163. m_timerToHideScrollAreaSet = true;
  1164. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);
  1165. //Start looking to hide the scroll bars
  1166. SetTimer(TIMER_HIDE_SCROL, 1000, NULL);
  1167. }
  1168. KillTimer(TIMER_SHOW_SCROLL);
  1169. callBase = false;
  1170. }
  1171. break;
  1172. }
  1173. if(callBase)
  1174. {
  1175. CListCtrl::OnTimer(nIDEvent);
  1176. }
  1177. }
  1178. void CQListCtrl::SetLogFont(LOGFONT &font)
  1179. {
  1180. m_Font.DeleteObject();
  1181. m_boldFont.DeleteObject();
  1182. m_Font.CreateFontIndirect(&font);
  1183. font.lfWeight = 600;
  1184. m_boldFont.CreateFontIndirect(&font);
  1185. SetFont(&m_Font);
  1186. }
  1187. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1188. {
  1189. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  1190. }
  1191. BOOL CQListCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  1192. {
  1193. return CListCtrl::OnMouseWheel(nFlags, zDelta, pt);
  1194. }
  1195. BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  1196. {
  1197. NMLVCACHEHINT* pcachehint = NULL;
  1198. if(message == WM_NOTIFY)
  1199. {
  1200. NMHDR* phdr = (NMHDR*)lParam;
  1201. switch(phdr->code)
  1202. {
  1203. case LVN_ODCACHEHINT:
  1204. pcachehint= (NMLVCACHEHINT*) phdr;
  1205. GetParent()->SendMessage(NM_FILL_REST_OF_LIST, pcachehint->iFrom, pcachehint->iTo);
  1206. return FALSE;
  1207. }
  1208. }
  1209. return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
  1210. }
  1211. BOOL CQListCtrl::OnItemDeleted(long lID)
  1212. {
  1213. BOOL bRet2 = m_RTFData.RemoveKey(lID);
  1214. return (bRet2);
  1215. }
  1216. void CQListCtrl::OnMouseMove(UINT nFlags, CPoint point)
  1217. {
  1218. if(g_Opt.m_showScrollBar == FALSE)
  1219. {
  1220. CRect crWindow;
  1221. this->GetWindowRect(&crWindow);
  1222. ScreenToClient(&crWindow);
  1223. crWindow.right -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1224. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1225. if(MouseInScrollBarArea(crWindow, point))
  1226. {
  1227. if((GetTickCount() - m_mouseOverScrollAreaStart) > 500)
  1228. {
  1229. SetTimer(TIMER_SHOW_SCROLL, 500, NULL);
  1230. m_mouseOverScrollAreaStart = GetTickCount();
  1231. }
  1232. }
  1233. else
  1234. {
  1235. if(m_timerToHideScrollAreaSet)
  1236. {
  1237. StopHideScrollBarTimer();
  1238. }
  1239. KillTimer(TIMER_SHOW_SCROLL);
  1240. }
  1241. }
  1242. }
  1243. bool CQListCtrl::MouseInScrollBarArea(CRect crWindow, CPoint point)
  1244. {
  1245. CRect crRight(crWindow);
  1246. CRect crBottom(crWindow);
  1247. crRight.left = crRight.right - theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1248. crBottom.top = crBottom.bottom - theApp.m_metrics.ScaleY(::GetSystemMetrics(SM_CYHSCROLL));
  1249. /*CString cs;
  1250. cs.Format(_T("point.x: %d, Width: %d, Height: %d\n"), point.x, crWindow.Width(), crWindow.Height());
  1251. OutputDebugString(cs);*/
  1252. if(crRight.PtInRect(point) || crBottom.PtInRect(point))
  1253. {
  1254. return true;
  1255. }
  1256. return false;
  1257. }
  1258. void CQListCtrl::StopHideScrollBarTimer()
  1259. {
  1260. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
  1261. m_timerToHideScrollAreaSet = false;
  1262. KillTimer(TIMER_HIDE_SCROL);
  1263. }
  1264. void CQListCtrl::SetSearchText(CString text)
  1265. {
  1266. m_searchText = text;
  1267. }
  1268. void CQListCtrl::HidePopup()
  1269. {
  1270. if(VALID_TOOLTIP)
  1271. m_pToolTip->Hide();
  1272. }
  1273. BOOL CQListCtrl::IsToolTipWindowVisible()
  1274. {
  1275. return ::IsWindowVisible(m_toolTipHwnd);
  1276. }
  1277. BOOL CQListCtrl::IsToolTipWindowFocus()
  1278. {
  1279. return ::GetFocus() == m_toolTipHwnd ||
  1280. ::GetParent(::GetFocus()) == m_toolTipHwnd;
  1281. }