QListCtrl.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594
  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. //::SendMessage(pNMHDR->hwndFrom, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELPARAM(32000, 0));
  548. // Use Item's name as the tool tip. Change this for something different.
  549. // Like use its file size, etc.
  550. GetToolTipText((int)nID-1, strTipText);
  551. //Replace the tabs with spaces, the tooltip didn't like the \t s
  552. strTipText.Replace(_T("\t"), _T(" "));
  553. int nLength = strTipText.GetLength()+2;
  554. #ifndef _UNICODE
  555. if (pNMHDR->code == TTN_NEEDTEXTA)
  556. {
  557. if(m_pchTip != NULL)
  558. delete m_pchTip;
  559. m_pchTip = new TCHAR[nLength];
  560. lstrcpyn(m_pchTip, strTipText, nLength-1);
  561. m_pchTip[nLength-1] = 0;
  562. pTTTW->lpszText = (WCHAR*)m_pchTip;
  563. }
  564. else
  565. {
  566. if(m_pwchTip != NULL)
  567. delete m_pwchTip;
  568. m_pwchTip = new WCHAR[nLength];
  569. _mbstowcsz(m_pwchTip, strTipText, nLength-1);
  570. m_pwchTip[nLength-1] = 0; // end of text
  571. pTTTW->lpszText = (WCHAR*)m_pwchTip;
  572. }
  573. #else
  574. if(pNMHDR->code == TTN_NEEDTEXTA)
  575. {
  576. if(m_pchTip != NULL)
  577. delete m_pchTip;
  578. m_pchTip = new TCHAR[nLength];
  579. STRNCPY(m_pchTip, strTipText, nLength-1);
  580. m_pchTip[nLength-1] = 0; // end of text
  581. pTTTW->lpszText = (LPTSTR)m_pchTip;
  582. }
  583. else
  584. {
  585. if(m_pwchTip != NULL)
  586. delete m_pwchTip;
  587. m_pwchTip = new WCHAR[nLength];
  588. lstrcpyn(m_pwchTip, strTipText, nLength-1);
  589. m_pwchTip[nLength-1] = 0;
  590. pTTTW->lpszText = (LPTSTR) m_pwchTip;
  591. }
  592. #endif
  593. *pResult = 0;
  594. return TRUE; // message was handled
  595. }
  596. INT_PTR CQListCtrl::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
  597. {
  598. CRect rect;
  599. GetClientRect(&rect);
  600. if(rect.PtInRect(point))
  601. {
  602. if(GetItemCount())
  603. {
  604. int nTopIndex = GetTopIndex();
  605. int nBottomIndex = nTopIndex + GetCountPerPage();
  606. if(nBottomIndex > GetItemCount()) nBottomIndex = GetItemCount();
  607. for(int nIndex = nTopIndex; nIndex <= nBottomIndex; nIndex++)
  608. {
  609. GetItemRect(nIndex, rect, LVIR_BOUNDS);
  610. if(rect.PtInRect(point))
  611. {
  612. pTI->hwnd = m_hWnd;
  613. pTI->uId = (UINT)(nIndex+1);
  614. pTI->lpszText = LPSTR_TEXTCALLBACK;
  615. pTI->rect = rect;
  616. pTI->uFlags = TTF_TRANSPARENT;
  617. return pTI->uId;
  618. }
  619. }
  620. }
  621. }
  622. return -1;
  623. }
  624. int CQListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  625. {
  626. if (CListCtrl::OnCreate(lpCreateStruct) == -1)
  627. return -1;
  628. EnableToolTips();
  629. m_pToolTip = new CToolTipEx;
  630. m_pToolTip->Create(this);
  631. m_pToolTip->SetNotifyWnd(GetParent());
  632. return 0;
  633. }
  634. BOOL CQListCtrl::PreTranslateMessage(MSG* pMsg)
  635. {
  636. CAccel a;
  637. if(m_Accels.OnMsg(pMsg, a))
  638. {
  639. switch(a.Cmd)
  640. {
  641. case COPY_BUFFER_HOT_KEY_1_ID:
  642. PutSelectedItemOnDittoCopyBuffer(0);
  643. break;
  644. case COPY_BUFFER_HOT_KEY_2_ID:
  645. PutSelectedItemOnDittoCopyBuffer(1);
  646. break;
  647. case COPY_BUFFER_HOT_KEY_3_ID:
  648. PutSelectedItemOnDittoCopyBuffer(2);
  649. break;
  650. default:
  651. if(a.RefId == CHotKey::PASTE_OPEN_CLIP)
  652. {
  653. GetParent()->SendMessage(NM_SELECT_DB_ID, a.Cmd, 0);
  654. }
  655. else if(a.RefId == CHotKey::MOVE_TO_GROUP)
  656. {
  657. GetParent()->SendMessage(NM_MOVE_TO_GROUP, a.Cmd, 0);
  658. }
  659. }
  660. return TRUE;
  661. }
  662. if(VALID_TOOLTIP)
  663. {
  664. if(m_pToolTip->OnMsg(pMsg))
  665. return TRUE;
  666. }
  667. switch(pMsg->message)
  668. {
  669. case WM_KEYDOWN:
  670. if(HandleKeyDown(pMsg->wParam, pMsg->lParam))
  671. return TRUE;
  672. break; // end case WM_KEYDOWN
  673. case WM_VSCROLL:
  674. ASSERT(FALSE);
  675. break;
  676. } // end switch(pMsg->message)
  677. return CListCtrl::PreTranslateMessage(pMsg);
  678. }
  679. BOOL CQListCtrl::HandleKeyDown(WPARAM wParam, LPARAM lParam)
  680. {
  681. if(VALID_TOOLTIP)
  682. {
  683. MSG Msg;
  684. Msg.lParam = lParam;
  685. Msg.wParam = wParam;
  686. Msg.message = WM_KEYDOWN;
  687. if(m_pToolTip->OnMsg(&Msg))
  688. return TRUE;
  689. }
  690. WPARAM vk = wParam;
  691. switch( vk )
  692. {
  693. case 'X': // Ctrl-X = Cut (prepare for moving the items into a Group)
  694. if(CONTROL_PRESSED)
  695. {
  696. LoadCopyOrCutToClipboard();
  697. theApp.IC_Cut(); // uses selection
  698. return TRUE;
  699. }
  700. break;
  701. case 'C': // Ctrl-C = Copy (prepare for copying the items into a Group)
  702. if(CONTROL_PRESSED)
  703. {
  704. LoadCopyOrCutToClipboard();
  705. theApp.IC_Copy(); // uses selection
  706. return TRUE;
  707. }
  708. break;
  709. case 'V': // Ctrl-V = Paste (actually performs the copy or move of items into the current Group)
  710. if(CONTROL_PRESSED)
  711. {
  712. theApp.IC_Paste();
  713. return TRUE;
  714. }
  715. break;
  716. case 'A': // Ctrl-A = Select All
  717. if(CONTROL_PRESSED)
  718. {
  719. int nCount = GetItemCount();
  720. for(int i = 0; i < nCount; i++)
  721. {
  722. SetSelection(i);
  723. }
  724. return TRUE;
  725. }
  726. break;
  727. case VK_HOME:
  728. SetListPos(0);
  729. break;
  730. } // end switch(vk)
  731. return FALSE;
  732. }
  733. void CQListCtrl::LoadCopyOrCutToClipboard()
  734. {
  735. ARRAY arr;
  736. GetSelectionItemData(arr);
  737. INT_PTR count = arr.GetSize();
  738. if(count <= 0)
  739. return;
  740. CProcessPaste paste;
  741. //Don't send the paste just load it into memory
  742. paste.m_bSendPaste = false;
  743. if(count > 1)
  744. paste.GetClipIDs().Copy(arr);
  745. else
  746. paste.GetClipIDs().Add(arr[0]);
  747. //Don't move these to the top
  748. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  749. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  750. paste.DoPaste();
  751. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  752. }
  753. bool CQListCtrl::PostEventLoadedCheckDescription(int updatedRow)
  754. {
  755. bool loadedClip = false;
  756. if (VALID_TOOLTIP)
  757. {
  758. int toolTipClipId = m_pToolTip->GetClipId();
  759. int toolTipClipRow = m_pToolTip->GetClipRow();
  760. if (toolTipClipRow >= 0)
  761. {
  762. log(StrF(_T("PostEventLoadedCheckDescription refreshRow: %d tt_row: %d tt_id: %d"), updatedRow, toolTipClipRow, toolTipClipId));
  763. }
  764. //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
  765. //see if we need to show this rows description
  766. if (toolTipClipId <= 0 &&
  767. toolTipClipRow == updatedRow &&
  768. ::IsWindow(m_toolTipHwnd))
  769. {
  770. ShowFullDescription(false, true);
  771. loadedClip = true;
  772. }
  773. }
  774. return loadedClip;
  775. }
  776. bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
  777. {
  778. if (this->GetSelectedCount() == 0)
  779. {
  780. return false;
  781. }
  782. int clipRow = this->GetCaret();
  783. int clipId = this->GetItemData(clipRow);
  784. log(StrF(_T("Show full description row: %d id: %d"), clipRow, clipId));
  785. if(VALID_TOOLTIP &&
  786. clipId > 0 &&
  787. m_pToolTip->GetClipId() == clipId &&
  788. ::IsWindow(m_toolTipHwnd))
  789. {
  790. return false;
  791. }
  792. int nItem = GetCaret();
  793. CRect rc, crWindow;
  794. GetWindowRect(&crWindow);
  795. GetItemRect(nItem, rc, LVIR_BOUNDS);
  796. ClientToScreen(rc);
  797. CPoint pt;
  798. if(CGetSetOptions::GetRememberDescPos())
  799. {
  800. CGetSetOptions::GetDescWndPoint(pt);
  801. }
  802. else if(bFromAuto == false)
  803. {
  804. pt = CPoint(rc.left, rc.bottom);
  805. }
  806. else
  807. {
  808. pt = CPoint((crWindow.left + (crWindow.right - crWindow.left)/2), rc.bottom);
  809. }
  810. CString csDescription;
  811. GetToolTipText(nItem, csDescription);
  812. if (m_pToolTip == NULL ||
  813. fromNextPrev == false ||
  814. ::IsWindow(m_toolTipHwnd) == FALSE)
  815. {
  816. m_pToolTip->DestroyWindow();
  817. m_pToolTip = new CToolTipEx;
  818. m_pToolTip->Create(this);
  819. m_toolTipHwnd = m_pToolTip->GetSafeHwnd();
  820. m_pToolTip->SetNotifyWnd(GetParent());
  821. }
  822. else if(VALID_TOOLTIP)
  823. {
  824. CRect r;
  825. m_pToolTip->GetWindowRect(r);
  826. pt = r.TopLeft();
  827. m_pToolTip->SetBitmap(NULL);
  828. m_pToolTip->SetRTFText("");
  829. m_pToolTip->SetToolTipText(_T(""));
  830. }
  831. if(VALID_TOOLTIP)
  832. {
  833. m_pToolTip->SetClipId(clipId);
  834. m_pToolTip->SetClipRow(clipRow);
  835. m_pToolTip->SetSearchText(m_searchText);
  836. m_pToolTip->SetClipData(_T(""));
  837. m_pToolTip->SetToolTipText(_T(""));
  838. m_pToolTip->SetRTFText(" ");
  839. bool bSetPlainText = false;
  840. CClipFormat Clip;
  841. try
  842. {
  843. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, lDate, lastPasteDate, lDontAutoDelete, QuickPasteText, lShortCut, globalShortCut, stickyClipOrder, stickyClipGroupOrder FROM Main WHERE lID = %d"), clipId);
  844. if (q.eof() == false)
  845. {
  846. CString clipData;
  847. COleDateTime time((time_t)q.getIntField(_T("lDate")));
  848. clipData += "Added: " + time.Format();
  849. COleDateTime modified((time_t)q.getIntField(_T("lastPasteDate")));
  850. clipData += _T(" | Last Used: ") + modified.Format();
  851. if (q.getIntField(_T("lDontAutoDelete")) > 0)
  852. {
  853. clipData += _T(" | Never Auto Delete");
  854. }
  855. CString csQuickPaste = q.getStringField(_T("QuickPasteText"));
  856. if (csQuickPaste.IsEmpty() == FALSE)
  857. {
  858. clipData += _T(" | Quick Paste = ");
  859. clipData += csQuickPaste;
  860. }
  861. int shortCut = q.getIntField(_T("lShortCut"));
  862. if (shortCut > 0)
  863. {
  864. clipData += _T(" | ");
  865. clipData += CHotKey::GetHotKeyDisplayStatic(shortCut);
  866. BOOL globalShortCut = q.getIntField(_T("globalShortCut"));
  867. if (globalShortCut)
  868. {
  869. clipData += _T(" - Global Shortcut Key");
  870. }
  871. }
  872. if (theApp.m_GroupID > 0)
  873. {
  874. int sticky = q.getIntField(_T("stickyClipGroupOrder"));
  875. if (sticky != INVALID_STICKY)
  876. {
  877. clipData += _T(" | ");
  878. clipData += _T(" - Sticky In Group");
  879. }
  880. }
  881. else
  882. {
  883. int sticky = q.getIntField(_T("stickyClipOrder"));
  884. if (sticky != INVALID_STICKY)
  885. {
  886. clipData += _T(" | ");
  887. clipData += _T(" - Sticky");
  888. }
  889. }
  890. m_pToolTip->SetClipData(clipData);
  891. }
  892. }
  893. CATCH_SQLITE_EXCEPTION
  894. Clip.m_cfType = CF_UNICODETEXT;
  895. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  896. {
  897. LPVOID pvData = GlobalLock(Clip.m_hgData);
  898. if(pvData)
  899. {
  900. CString csText = (WCHAR*)pvData;
  901. m_pToolTip->SetToolTipText(csText);
  902. bSetPlainText = true;
  903. }
  904. GlobalUnlock(Clip.m_hgData);
  905. Clip.Free();
  906. Clip.Clear();
  907. }
  908. if(bSetPlainText == false)
  909. {
  910. Clip.m_cfType = CF_TEXT;
  911. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  912. {
  913. LPVOID pvData = GlobalLock(Clip.m_hgData);
  914. if(pvData)
  915. {
  916. CString csText = (char*)pvData;
  917. m_pToolTip->SetToolTipText(csText);
  918. bSetPlainText = true;
  919. }
  920. GlobalUnlock(Clip.m_hgData);
  921. Clip.Free();
  922. Clip.Clear();
  923. }
  924. }
  925. if(bSetPlainText == false)
  926. {
  927. m_pToolTip->SetToolTipText(csDescription);
  928. }
  929. Clip.m_cfType = RegisterClipboardFormat(CF_RTF);
  930. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  931. {
  932. LPVOID pvData = GlobalLock(Clip.m_hgData);
  933. if(pvData)
  934. {
  935. m_pToolTip->SetRTFText((char*)pvData);
  936. }
  937. GlobalUnlock(Clip.m_hgData);
  938. Clip.Free();
  939. Clip.Clear();
  940. }
  941. Clip.m_cfType = CF_DIB;
  942. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  943. {
  944. CBitmap *pBitMap = new CBitmap;
  945. if(pBitMap)
  946. {
  947. CRect rcItem;
  948. GetWindowRect(rcItem);
  949. CDC *pDC = GetDC();;
  950. CBitmapHelper::GetCBitmap(&Clip, pDC, pBitMap, MAXINT);
  951. ReleaseDC(pDC);
  952. //Tooltip wnd will release
  953. m_pToolTip->SetBitmap(pBitMap);
  954. }
  955. Clip.Free();
  956. Clip.Clear();
  957. }
  958. m_pToolTip->Show(pt);
  959. }
  960. return true;
  961. }
  962. void CQListCtrl::GetToolTipText(int nItem, CString &csText)
  963. {
  964. CWnd* pParent=GetParent();
  965. if(pParent && (pParent->GetSafeHwnd() != NULL))
  966. {
  967. CQListToolTipText info;
  968. memset(&info, 0, sizeof(info));
  969. info.hdr.code = NM_GETTOOLTIPTEXT;
  970. info.hdr.hwndFrom = GetSafeHwnd();
  971. info.hdr.idFrom = GetDlgCtrlID();
  972. info.lItem = nItem;
  973. //plus 100 for extra info - shortcut and such
  974. info.cchTextMax = g_Opt.m_bDescTextSize + 100;
  975. info.pszText = csText.GetBufferSetLength(info.cchTextMax);
  976. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  977. csText.ReleaseBuffer();
  978. }
  979. }
  980. BOOL CQListCtrl::GetClipData(int nItem, CClipFormat &Clip)
  981. {
  982. return theApp.GetClipData(GetItemData(nItem), Clip);
  983. }
  984. DWORD CQListCtrl::GetItemData(int nItem)
  985. {
  986. if((GetStyle() & LVS_OWNERDATA))
  987. {
  988. CWnd* pParent=GetParent();
  989. if(pParent && (pParent->GetSafeHwnd() != NULL))
  990. {
  991. LV_DISPINFO info;
  992. memset(&info, 0, sizeof(info));
  993. info.hdr.code = LVN_GETDISPINFO;
  994. info.hdr.hwndFrom = GetSafeHwnd();
  995. info.hdr.idFrom = GetDlgCtrlID();
  996. info.item.iItem = nItem;
  997. info.item.lParam = -1;
  998. info.item.mask = LVIF_PARAM;
  999. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  1000. return (DWORD)info.item.lParam;
  1001. }
  1002. }
  1003. return (DWORD)CListCtrl::GetItemData(nItem);
  1004. }
  1005. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_DIB_ClipFormat(int nItem)
  1006. {
  1007. CClipFormatQListCtrl *format = NULL;
  1008. CWnd* pParent=GetParent();
  1009. if(pParent && (pParent->GetSafeHwnd() != NULL))
  1010. {
  1011. LV_DISPINFO info;
  1012. memset(&info, 0, sizeof(info));
  1013. info.hdr.code = LVN_GETDISPINFO;
  1014. info.hdr.hwndFrom = GetSafeHwnd();
  1015. info.hdr.idFrom = GetDlgCtrlID();
  1016. info.item.iItem = nItem;
  1017. info.item.lParam = NULL;
  1018. info.item.mask = LVIF_CF_DIB;
  1019. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  1020. if(info.item.lParam != NULL)
  1021. {
  1022. format = (CClipFormatQListCtrl *)info.item.lParam;
  1023. }
  1024. }
  1025. return format;
  1026. }
  1027. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_RTF_ClipFormat(int nItem)
  1028. {
  1029. CClipFormatQListCtrl *format = NULL;
  1030. CWnd* pParent=GetParent();
  1031. if(pParent && (pParent->GetSafeHwnd() != NULL))
  1032. {
  1033. LV_DISPINFO info;
  1034. memset(&info, 0, sizeof(info));
  1035. info.hdr.code = LVN_GETDISPINFO;
  1036. info.hdr.hwndFrom = GetSafeHwnd();
  1037. info.hdr.idFrom = GetDlgCtrlID();
  1038. info.item.iItem = nItem;
  1039. info.item.lParam = NULL;
  1040. info.item.mask = LVIF_CF_RICHTEXT;
  1041. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  1042. if(info.item.lParam != NULL)
  1043. {
  1044. format = (CClipFormatQListCtrl *)info.item.lParam;
  1045. }
  1046. }
  1047. return format;
  1048. }
  1049. void CQListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1050. {
  1051. CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
  1052. }
  1053. void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate, CppSQLite3DB &db)
  1054. {
  1055. m_Accels.RemoveAll();
  1056. if(bCreate)
  1057. {
  1058. CMainTableFunctions::LoadAcceleratorKeys(m_Accels, db);
  1059. LoadDittoCopyBufferHotkeys();
  1060. }
  1061. }
  1062. void CQListCtrl::LoadDittoCopyBufferHotkeys()
  1063. {
  1064. CCopyBufferItem Item;
  1065. CAccel a;
  1066. g_Opt.GetCopyBufferItem(0, Item);
  1067. if(Item.m_lCopyHotKey > 0)
  1068. {
  1069. a.Cmd = COPY_BUFFER_HOT_KEY_1_ID;
  1070. a.Key = Item.m_lCopyHotKey;
  1071. m_Accels.AddAccel(a);
  1072. }
  1073. g_Opt.GetCopyBufferItem(1, Item);
  1074. if(Item.m_lCopyHotKey > 0)
  1075. {
  1076. a.Cmd = COPY_BUFFER_HOT_KEY_2_ID;
  1077. a.Key = Item.m_lCopyHotKey;
  1078. m_Accels.AddAccel(a);
  1079. }
  1080. g_Opt.GetCopyBufferItem(2, Item);
  1081. if(Item.m_lCopyHotKey > 0)
  1082. {
  1083. a.Cmd = COPY_BUFFER_HOT_KEY_3_ID;
  1084. a.Key = Item.m_lCopyHotKey;
  1085. m_Accels.AddAccel(a);
  1086. }
  1087. }
  1088. void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
  1089. {
  1090. CListCtrl::OnKillFocus(pNewWnd);
  1091. //if(FocusOnToolTip() == FALSE)
  1092. //m_pToolTip->Hide();
  1093. }
  1094. HWND CQListCtrl::GetToolTipHWnd()
  1095. {
  1096. if(VALID_TOOLTIP)
  1097. return m_pToolTip->GetSafeHwnd();
  1098. return NULL;
  1099. }
  1100. BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = 0 */)
  1101. {
  1102. return CListCtrl::SetItemCountEx(iCount, dwFlags);
  1103. }
  1104. void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
  1105. {
  1106. NMLISTVIEW *pnmv = (NMLISTVIEW *) pNMHDR;
  1107. if((pnmv->uNewState == 3) ||
  1108. (pnmv->uNewState == 1))
  1109. {
  1110. if (VALID_TOOLTIP &&
  1111. ::IsWindowVisible(m_pToolTip->m_hWnd))
  1112. {
  1113. this->ShowFullDescription(false, true);
  1114. }
  1115. if(g_Opt.m_bAllwaysShowDescription)
  1116. {
  1117. KillTimer(TIMER_SHOW_PROPERTIES);
  1118. SetTimer(TIMER_SHOW_PROPERTIES, 300, NULL);
  1119. }
  1120. if(GetSelectedCount() > 0 )
  1121. theApp.SetStatus(NULL, FALSE);
  1122. }
  1123. if(GetSelectedCount() == this->GetItemCount())
  1124. {
  1125. if(m_allSelected == false)
  1126. {
  1127. Log(StrF(_T("List box Select All")));
  1128. GetParent()->SendMessage(NM_ALL_SELECTED, 0, 0);
  1129. m_allSelected = true;
  1130. }
  1131. }
  1132. else if(m_allSelected == true)
  1133. {
  1134. Log(StrF(_T("List box REMOVED Select All")));
  1135. m_allSelected = false;
  1136. }
  1137. }
  1138. void CQListCtrl::OnTimer(UINT_PTR nIDEvent)
  1139. {
  1140. //http://support.microsoft.com/kb/200054
  1141. //OnTimer() Is Not Called Repeatedly for a List Control
  1142. bool callBase = true;
  1143. switch(nIDEvent)
  1144. {
  1145. case TIMER_SHOW_PROPERTIES:
  1146. {
  1147. if( theApp.m_bShowingQuickPaste )
  1148. ShowFullDescription(true);
  1149. KillTimer(TIMER_SHOW_PROPERTIES);
  1150. callBase = false;
  1151. }
  1152. break;
  1153. case TIMER_HIDE_SCROL:
  1154. {
  1155. CPoint cursorPos;
  1156. GetCursorPos(&cursorPos);
  1157. CRect crWindow;
  1158. this->GetWindowRect(&crWindow);
  1159. //check and see if they moved out of the scroll area
  1160. //If they did tell our parent so
  1161. if(MouseInScrollBarArea(crWindow, cursorPos) == false)
  1162. {
  1163. StopHideScrollBarTimer();
  1164. }
  1165. callBase = false;
  1166. }
  1167. break;
  1168. case TIMER_SHOW_SCROLL:
  1169. {
  1170. CPoint cursorPos;
  1171. GetCursorPos(&cursorPos);
  1172. CRect crWindow;
  1173. this->GetWindowRect(&crWindow);
  1174. //Adjust for the v-scroll bar being off of the screen
  1175. //crWindow.right -= theApp.m_metrics.ScaleX(GetSystemMetrics(SM_CXVSCROLL));
  1176. //crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1177. //Check and see if we are still in the cursor area
  1178. if(MouseInScrollBarArea(crWindow, cursorPos))
  1179. {
  1180. m_timerToHideScrollAreaSet = true;
  1181. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);
  1182. //Start looking to hide the scroll bars
  1183. SetTimer(TIMER_HIDE_SCROL, 1000, NULL);
  1184. }
  1185. KillTimer(TIMER_SHOW_SCROLL);
  1186. callBase = false;
  1187. }
  1188. break;
  1189. }
  1190. if(callBase)
  1191. {
  1192. CListCtrl::OnTimer(nIDEvent);
  1193. }
  1194. }
  1195. void CQListCtrl::SetLogFont(LOGFONT &font)
  1196. {
  1197. m_Font.DeleteObject();
  1198. m_boldFont.DeleteObject();
  1199. m_Font.CreateFontIndirect(&font);
  1200. font.lfWeight = 600;
  1201. m_boldFont.CreateFontIndirect(&font);
  1202. SetFont(&m_Font);
  1203. }
  1204. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1205. {
  1206. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  1207. }
  1208. BOOL CQListCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  1209. {
  1210. return CListCtrl::OnMouseWheel(nFlags, zDelta, pt);
  1211. }
  1212. BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  1213. {
  1214. NMLVCACHEHINT* pcachehint = NULL;
  1215. if(message == WM_NOTIFY)
  1216. {
  1217. NMHDR* phdr = (NMHDR*)lParam;
  1218. switch(phdr->code)
  1219. {
  1220. case LVN_ODCACHEHINT:
  1221. pcachehint= (NMLVCACHEHINT*) phdr;
  1222. GetParent()->SendMessage(NM_FILL_REST_OF_LIST, pcachehint->iFrom, pcachehint->iTo);
  1223. return FALSE;
  1224. }
  1225. }
  1226. return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
  1227. }
  1228. BOOL CQListCtrl::OnItemDeleted(long lID)
  1229. {
  1230. BOOL bRet2 = m_RTFData.RemoveKey(lID);
  1231. return (bRet2);
  1232. }
  1233. void CQListCtrl::OnMouseMove(UINT nFlags, CPoint point)
  1234. {
  1235. if(g_Opt.m_showScrollBar == FALSE)
  1236. {
  1237. CPoint cursorPos;
  1238. GetCursorPos(&cursorPos);
  1239. CRect crWindow;
  1240. this->GetWindowRect(&crWindow);
  1241. ScreenToClient(&crWindow);
  1242. //crWindow.right -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1243. //crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1244. if(MouseInScrollBarArea(crWindow, point))
  1245. {
  1246. if((GetTickCount() - m_mouseOverScrollAreaStart) > 500)
  1247. {
  1248. SetTimer(TIMER_SHOW_SCROLL, 500, NULL);
  1249. m_mouseOverScrollAreaStart = GetTickCount();
  1250. }
  1251. }
  1252. else
  1253. {
  1254. if(m_timerToHideScrollAreaSet)
  1255. {
  1256. StopHideScrollBarTimer();
  1257. }
  1258. KillTimer(TIMER_SHOW_SCROLL);
  1259. }
  1260. }
  1261. }
  1262. bool CQListCtrl::MouseInScrollBarArea(CRect crWindow, CPoint point)
  1263. {
  1264. CRect crRight(crWindow);
  1265. CRect crBottom(crWindow);
  1266. crRight.left = crRight.right - theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1267. crBottom.top = crBottom.bottom - theApp.m_metrics.ScaleY(::GetSystemMetrics(SM_CYHSCROLL));
  1268. /*CString cs;
  1269. cs.Format(_T("point.x: %d, Width: %d, Height: %d\n"), point.x, crWindow.Width(), crWindow.Height());
  1270. OutputDebugString(cs);*/
  1271. if(crRight.PtInRect(point) || crBottom.PtInRect(point))
  1272. {
  1273. return true;
  1274. }
  1275. return false;
  1276. }
  1277. void CQListCtrl::StopHideScrollBarTimer()
  1278. {
  1279. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
  1280. m_timerToHideScrollAreaSet = false;
  1281. KillTimer(TIMER_HIDE_SCROL);
  1282. }
  1283. void CQListCtrl::SetSearchText(CString text)
  1284. {
  1285. m_searchText = text;
  1286. }
  1287. void CQListCtrl::HidePopup(bool checkShowPersistant)
  1288. {
  1289. if (VALID_TOOLTIP)
  1290. {
  1291. if (checkShowPersistant == false ||
  1292. m_pToolTip->GetShowPersistant() == false)
  1293. {
  1294. m_pToolTip->Hide();
  1295. }
  1296. }
  1297. }
  1298. BOOL CQListCtrl::IsToolTipWindowVisible()
  1299. {
  1300. return ::IsWindowVisible(m_toolTipHwnd);
  1301. }
  1302. BOOL CQListCtrl::IsToolTipWindowFocus()
  1303. {
  1304. return ::GetFocus() == m_toolTipHwnd ||
  1305. ::GetParent(::GetFocus()) == m_toolTipHwnd;
  1306. }