QListCtrl.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  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. m_pToolTipActions = NULL;
  62. }
  63. CQListCtrl::~CQListCtrl()
  64. {
  65. if(m_pchTip != NULL)
  66. delete m_pchTip;
  67. if(m_pwchTip != NULL)
  68. delete m_pwchTip;
  69. if( m_SmallFont )
  70. ::DeleteObject( m_SmallFont );
  71. m_Font.DeleteObject();
  72. m_boldFont.DeleteObject();
  73. if(m_pFormatter)
  74. {
  75. delete m_pFormatter;
  76. m_pFormatter = NULL;
  77. }
  78. }
  79. // returns the position 1-10 if the index is in the FirstTen block else -1
  80. int CQListCtrl::GetFirstTenNum( int index )
  81. {
  82. // set firstTenNum to the first ten number (1-10) corresponding to the given index
  83. int firstTenNum = -1; // -1 means that nItem is not in the FirstTen block.
  84. int count = GetItemCount();
  85. if( m_bStartTop )
  86. {
  87. if( 0 <= index && index <= 9 )
  88. firstTenNum = index + 1;
  89. }
  90. else // we are starting at the bottom and going up
  91. {
  92. int idxStartFirstTen = count-10; // start of the FirstTen block
  93. // if index is within the FirstTen block
  94. if( idxStartFirstTen <= index && index < count )
  95. firstTenNum = count - index;
  96. }
  97. return firstTenNum;
  98. }
  99. // returns the list index corresponding to the given FirstTen position number.
  100. // (ret < 0) means that "num" is not in the FirstTen block
  101. int CQListCtrl::GetFirstTenIndex( int num )
  102. {
  103. if( num <= 0 || num > 10 )
  104. return -1;
  105. if( m_bStartTop )
  106. return num-1;
  107. // else we are starting at the bottom and going up
  108. int count = GetItemCount();
  109. return count - num;
  110. }
  111. BEGIN_MESSAGE_MAP(CQListCtrl, CListCtrl)
  112. //{{AFX_MSG_MAP(CQListCtrl)
  113. ON_NOTIFY_REFLECT(LVN_KEYDOWN, OnKeydown)
  114. ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdrawList)
  115. ON_WM_MOUSEMOVE()
  116. ON_WM_SYSKEYDOWN()
  117. ON_WM_ERASEBKGND()
  118. ON_WM_CREATE()
  119. ON_WM_HSCROLL()
  120. ON_WM_TIMER()
  121. ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnSelectionChange)
  122. ON_WM_VSCROLL()
  123. ON_WM_WINDOWPOSCHANGED()
  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_rtfFormater.m_hWnd == NULL)
  460. {
  461. m_rtfFormater.Create(_T(""), _T(""), WS_CHILD | WS_VSCROLL |
  462. WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_NOHIDESEL |
  463. ES_AUTOHSCROLL, CRect(0, 0, 0, 0), this, -1);
  464. }
  465. if(m_pFormatter)
  466. {
  467. char *pData = (char*)GlobalLock(pThumbnail->m_hgData);
  468. if(pData)
  469. {
  470. //somehow ms word places crazy rtf text onto the clipboard and our draw routine doesn't handle that
  471. //pass the rtf text into a richtext control and get it out and the contorl will clean the rtf so our routine can draw it
  472. m_rtfFormater.SetRTF((char*)pData);
  473. CString betterRTF = m_rtfFormater.GetRTF();
  474. CComBSTR bStr(betterRTF);
  475. m_pFormatter->put_RTFText(bStr);
  476. m_pFormatter->Draw(pDC->m_hDC, crRect);
  477. bRet = TRUE;
  478. }
  479. }
  480. return bRet;
  481. }
  482. // DrawBitMap loads a DIB from the DB, draws a crRect thumbnail of the image
  483. // to pDC and caches that thumbnail as a DIB in m_ThumbNails[ ItemID ].
  484. // ALL items are cached in m_ThumbNails (those without images are cached with NULL m_hgData)
  485. BOOL CQListCtrl::DrawBitMap(int nItem, CRect &crRect, CDC *pDC, const CString &csDescription)
  486. {
  487. if(g_Opt.m_bDrawThumbnail == FALSE)
  488. return FALSE;
  489. CClipFormatQListCtrl *format = GetItem_CF_DIB_ClipFormat(nItem);
  490. if(format != NULL)
  491. {
  492. HGLOBAL smallImage = format->GetDibFittingToHeight(pDC, crRect.Height());
  493. if(smallImage != NULL)
  494. {
  495. //Will return the width of the bitmap in nWidth
  496. int nWidth = 0;
  497. if(CBitmapHelper::DrawDIB(pDC, smallImage, crRect.left, crRect.top, nWidth))
  498. {
  499. // adjust the rect so other information can be drawn next to the thumbnail
  500. crRect.left += nWidth + 3;
  501. }
  502. }
  503. }
  504. else if(csDescription.Find(_T("CF_DIB")) == 0)
  505. {
  506. crRect.left += crRect.Height();
  507. }
  508. return TRUE;
  509. }
  510. void CQListCtrl::RefreshVisibleRows()
  511. {
  512. int nTopIndex = GetTopIndex();
  513. int nLastIndex = nTopIndex + GetCountPerPage();
  514. RedrawItems(nTopIndex, nLastIndex);
  515. }
  516. void CQListCtrl::RefreshRow(int row)
  517. {
  518. RedrawItems(row, row);
  519. }
  520. void CQListCtrl::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  521. {
  522. CListCtrl::OnSysKeyDown(nChar, nRepCnt, nFlags);
  523. }
  524. BOOL CQListCtrl::OnEraseBkgnd(CDC* pDC)
  525. {
  526. CRect rect;
  527. GetClientRect(&rect);
  528. CBrush myBrush(g_Opt.m_Theme.MainWindowBG()); // dialog background color
  529. CBrush *pOld = pDC->SelectObject(&myBrush);
  530. BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
  531. pDC->SelectObject(pOld); // restore old brush
  532. return bRes; // CDialog::OnEraseBkgnd(pDC);
  533. // Simply returning TRUE seems OK since we do custom item
  534. // painting. However, there is a pixel buffer around the
  535. // border of this control (not within the item rects)
  536. // which becomes visually corrupt if it is not erased.
  537. // In most cases, I do not notice the erasure, so I have kept
  538. // the call to CListCtrl::OnEraseBkgnd(pDC);
  539. // However, for some reason, bulk erasure is very noticeable when
  540. // shift-scrolling the page to select a block of items, so
  541. // I made a special case for that:
  542. //if(GetSelectedCount() >= 2)
  543. // return TRUE;
  544. //return CListCtrl::OnEraseBkgnd(pDC);
  545. }
  546. BOOL CQListCtrl::OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  547. {
  548. // need to handle both ANSI and UNICODE versions of the message
  549. TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
  550. TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
  551. CString strTipText;
  552. UINT_PTR nID = pNMHDR->idFrom;
  553. if(nID == 0) // Notification in NT from automatically
  554. return FALSE; // created tooltip
  555. ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 500);
  556. if (g_Opt.m_tooltipTimeout > 0)
  557. {
  558. ::SendMessage(pNMHDR->hwndFrom, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELPARAM(g_Opt.m_tooltipTimeout, 0));
  559. }
  560. // Use Item's name as the tool tip. Change this for something different.
  561. // Like use its file size, etc.
  562. GetToolTipText((int)nID-1, strTipText);
  563. //Replace the tabs with spaces, the tooltip didn't like the \t s
  564. strTipText.Replace(_T("\t"), _T(" "));
  565. int nLength = strTipText.GetLength()+2;
  566. #ifndef _UNICODE
  567. if (pNMHDR->code == TTN_NEEDTEXTA)
  568. {
  569. if(m_pchTip != NULL)
  570. delete m_pchTip;
  571. m_pchTip = new TCHAR[nLength];
  572. lstrcpyn(m_pchTip, strTipText, nLength-1);
  573. m_pchTip[nLength-1] = 0;
  574. pTTTW->lpszText = (WCHAR*)m_pchTip;
  575. }
  576. else
  577. {
  578. if(m_pwchTip != NULL)
  579. delete m_pwchTip;
  580. m_pwchTip = new WCHAR[nLength];
  581. _mbstowcsz(m_pwchTip, strTipText, nLength-1);
  582. m_pwchTip[nLength-1] = 0; // end of text
  583. pTTTW->lpszText = (WCHAR*)m_pwchTip;
  584. }
  585. #else
  586. if(pNMHDR->code == TTN_NEEDTEXTA)
  587. {
  588. if(m_pchTip != NULL)
  589. delete m_pchTip;
  590. m_pchTip = new TCHAR[nLength];
  591. STRNCPY(m_pchTip, strTipText, nLength-1);
  592. m_pchTip[nLength-1] = 0; // end of text
  593. pTTTW->lpszText = (LPTSTR)m_pchTip;
  594. }
  595. else
  596. {
  597. if(m_pwchTip != NULL)
  598. delete m_pwchTip;
  599. m_pwchTip = new WCHAR[nLength];
  600. lstrcpyn(m_pwchTip, strTipText, nLength-1);
  601. m_pwchTip[nLength-1] = 0;
  602. pTTTW->lpszText = (LPTSTR) m_pwchTip;
  603. }
  604. #endif
  605. *pResult = 0;
  606. return TRUE; // message was handled
  607. }
  608. INT_PTR CQListCtrl::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
  609. {
  610. CRect rect;
  611. GetClientRect(&rect);
  612. if(rect.PtInRect(point))
  613. {
  614. if(GetItemCount())
  615. {
  616. int nTopIndex = GetTopIndex();
  617. int nBottomIndex = nTopIndex + GetCountPerPage();
  618. if(nBottomIndex > GetItemCount()) nBottomIndex = GetItemCount();
  619. for(int nIndex = nTopIndex; nIndex <= nBottomIndex; nIndex++)
  620. {
  621. GetItemRect(nIndex, rect, LVIR_BOUNDS);
  622. if(rect.PtInRect(point))
  623. {
  624. pTI->hwnd = m_hWnd;
  625. pTI->uId = (UINT)(nIndex+1);
  626. pTI->lpszText = LPSTR_TEXTCALLBACK;
  627. pTI->rect = rect;
  628. pTI->uFlags = TTF_TRANSPARENT;
  629. return pTI->uId;
  630. }
  631. }
  632. }
  633. }
  634. return -1;
  635. }
  636. int CQListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  637. {
  638. if (CListCtrl::OnCreate(lpCreateStruct) == -1)
  639. return -1;
  640. if (g_Opt.m_tooltipTimeout > 0 ||
  641. g_Opt.m_tooltipTimeout == -1)
  642. {
  643. EnableToolTips();
  644. }
  645. else
  646. {
  647. EnableToolTips(FALSE);
  648. }
  649. m_pToolTip = new CToolTipEx;
  650. m_pToolTip->Create(this);
  651. m_pToolTip->SetNotifyWnd(GetParent());
  652. return 0;
  653. }
  654. BOOL CQListCtrl::PreTranslateMessage(MSG* pMsg)
  655. {
  656. CAccel a;
  657. if(m_Accels.OnMsg(pMsg, a))
  658. {
  659. switch(a.Cmd)
  660. {
  661. case COPY_BUFFER_HOT_KEY_1_ID:
  662. PutSelectedItemOnDittoCopyBuffer(0);
  663. break;
  664. case COPY_BUFFER_HOT_KEY_2_ID:
  665. PutSelectedItemOnDittoCopyBuffer(1);
  666. break;
  667. case COPY_BUFFER_HOT_KEY_3_ID:
  668. PutSelectedItemOnDittoCopyBuffer(2);
  669. break;
  670. default:
  671. if(a.RefId == CHotKey::PASTE_OPEN_CLIP)
  672. {
  673. GetParent()->SendMessage(NM_SELECT_DB_ID, a.Cmd, 0);
  674. }
  675. else if(a.RefId == CHotKey::MOVE_TO_GROUP)
  676. {
  677. GetParent()->SendMessage(NM_MOVE_TO_GROUP, a.Cmd, 0);
  678. }
  679. }
  680. return TRUE;
  681. }
  682. if(VALID_TOOLTIP)
  683. {
  684. if(m_pToolTip->OnMsg(pMsg))
  685. return TRUE;
  686. }
  687. switch(pMsg->message)
  688. {
  689. case WM_KEYDOWN:
  690. if(HandleKeyDown(pMsg->wParam, pMsg->lParam))
  691. return TRUE;
  692. break; // end case WM_KEYDOWN
  693. case WM_VSCROLL:
  694. ASSERT(FALSE);
  695. break;
  696. } // end switch(pMsg->message)
  697. return CListCtrl::PreTranslateMessage(pMsg);
  698. }
  699. BOOL CQListCtrl::HandleKeyDown(WPARAM wParam, LPARAM lParam)
  700. {
  701. if(VALID_TOOLTIP)
  702. {
  703. MSG Msg;
  704. Msg.lParam = lParam;
  705. Msg.wParam = wParam;
  706. Msg.message = WM_KEYDOWN;
  707. if(m_pToolTip->OnMsg(&Msg))
  708. return TRUE;
  709. }
  710. WPARAM vk = wParam;
  711. switch( vk )
  712. {
  713. case 'X': // Ctrl-X = Cut (prepare for moving the items into a Group)
  714. if(CONTROL_PRESSED)
  715. {
  716. LoadCopyOrCutToClipboard();
  717. theApp.IC_Cut(); // uses selection
  718. return TRUE;
  719. }
  720. break;
  721. case 'C': // Ctrl-C = Copy (prepare for copying the items into a Group)
  722. if(CONTROL_PRESSED)
  723. {
  724. LoadCopyOrCutToClipboard();
  725. theApp.IC_Copy(); // uses selection
  726. return TRUE;
  727. }
  728. break;
  729. case 'V': // Ctrl-V = Paste (actually performs the copy or move of items into the current Group)
  730. if(CONTROL_PRESSED)
  731. {
  732. theApp.IC_Paste();
  733. return TRUE;
  734. }
  735. break;
  736. case 'A': // Ctrl-A = Select All
  737. if(CONTROL_PRESSED)
  738. {
  739. int nCount = GetItemCount();
  740. for(int i = 0; i < nCount; i++)
  741. {
  742. SetSelection(i);
  743. }
  744. return TRUE;
  745. }
  746. break;
  747. case VK_HOME:
  748. SetListPos(0);
  749. break;
  750. } // end switch(vk)
  751. return FALSE;
  752. }
  753. void CQListCtrl::LoadCopyOrCutToClipboard()
  754. {
  755. ARRAY arr;
  756. GetSelectionItemData(arr);
  757. INT_PTR count = arr.GetSize();
  758. if(count <= 0)
  759. return;
  760. CProcessPaste paste;
  761. //Don't send the paste just load it into memory
  762. paste.m_bSendPaste = false;
  763. if(count > 1)
  764. paste.GetClipIDs().Copy(arr);
  765. else
  766. paste.GetClipIDs().Add(arr[0]);
  767. //Don't move these to the top
  768. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  769. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  770. paste.DoPaste();
  771. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  772. }
  773. bool CQListCtrl::PostEventLoadedCheckDescription(int updatedRow)
  774. {
  775. bool loadedClip = false;
  776. if (VALID_TOOLTIP)
  777. {
  778. int toolTipClipId = m_pToolTip->GetClipId();
  779. int toolTipClipRow = m_pToolTip->GetClipRow();
  780. if (toolTipClipRow >= 0)
  781. {
  782. log(StrF(_T("PostEventLoadedCheckDescription refreshRow: %d tt_row: %d tt_id: %d"), updatedRow, toolTipClipRow, toolTipClipId));
  783. }
  784. //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
  785. //see if we need to show this rows description
  786. if (toolTipClipId <= 0 &&
  787. toolTipClipRow == updatedRow &&
  788. ::IsWindow(m_toolTipHwnd))
  789. {
  790. ShowFullDescription(false, true);
  791. loadedClip = true;
  792. }
  793. }
  794. return loadedClip;
  795. }
  796. bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
  797. {
  798. if (this->GetSelectedCount() == 0)
  799. {
  800. return false;
  801. }
  802. int clipRow = this->GetCaret();
  803. int clipId = this->GetItemData(clipRow);
  804. log(StrF(_T("Show full description row: %d id: %d"), clipRow, clipId));
  805. if(VALID_TOOLTIP &&
  806. clipId > 0 &&
  807. m_pToolTip->GetClipId() == clipId &&
  808. ::IsWindow(m_toolTipHwnd))
  809. {
  810. return false;
  811. }
  812. int nItem = GetCaret();
  813. CRect rc, crWindow;
  814. GetWindowRect(&crWindow);
  815. GetItemRect(nItem, rc, LVIR_BOUNDS);
  816. ClientToScreen(rc);
  817. CPoint pt;
  818. if(CGetSetOptions::GetRememberDescPos())
  819. {
  820. CGetSetOptions::GetDescWndPoint(pt);
  821. }
  822. else if(bFromAuto == false)
  823. {
  824. pt = CPoint(rc.left, rc.bottom);
  825. }
  826. else
  827. {
  828. pt = CPoint((crWindow.left + (crWindow.right - crWindow.left)/2), rc.bottom);
  829. }
  830. CString csDescription;
  831. GetToolTipText(nItem, csDescription);
  832. if (m_pToolTip == NULL ||
  833. fromNextPrev == false ||
  834. ::IsWindow(m_toolTipHwnd) == FALSE)
  835. {
  836. m_pToolTip->DestroyWindow();
  837. m_pToolTip = new CToolTipEx;
  838. m_pToolTip->Create(this);
  839. m_toolTipHwnd = m_pToolTip->GetSafeHwnd();
  840. m_pToolTip->SetNotifyWnd(GetParent());
  841. }
  842. else if(VALID_TOOLTIP)
  843. {
  844. CRect r;
  845. m_pToolTip->GetWindowRectEx(r);
  846. pt = r.TopLeft();
  847. m_pToolTip->SetGdiplusBitmap(NULL);
  848. m_pToolTip->SetRTFText("");
  849. m_pToolTip->SetToolTipText(_T(""));
  850. }
  851. if(VALID_TOOLTIP)
  852. {
  853. m_pToolTip->SetTooltipActions(m_pToolTipActions);
  854. m_pToolTip->SetClipId(clipId);
  855. m_pToolTip->SetClipRow(clipRow);
  856. m_pToolTip->SetSearchText(m_searchText);
  857. m_pToolTip->SetClipData(_T(""));
  858. m_pToolTip->SetToolTipText(_T(""));
  859. m_pToolTip->SetRTFText(" ");
  860. bool bSetPlainText = false;
  861. CClipFormat Clip;
  862. try
  863. {
  864. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, lDate, lastPasteDate, lDontAutoDelete, QuickPasteText, lShortCut, globalShortCut, stickyClipOrder, stickyClipGroupOrder FROM Main WHERE lID = %d"), clipId);
  865. if (q.eof() == false)
  866. {
  867. CString clipData;
  868. COleDateTime time((time_t)q.getIntField(_T("lDate")));
  869. clipData += "Added: " + time.Format();
  870. COleDateTime modified((time_t)q.getIntField(_T("lastPasteDate")));
  871. clipData += _T(" | Last Used: ") + modified.Format();
  872. if (q.getIntField(_T("lDontAutoDelete")) > 0)
  873. {
  874. clipData += _T(" | Never Auto Delete");
  875. }
  876. CString csQuickPaste = q.getStringField(_T("QuickPasteText"));
  877. if (csQuickPaste.IsEmpty() == FALSE)
  878. {
  879. clipData += _T(" | Quick Paste = ");
  880. clipData += csQuickPaste;
  881. }
  882. int shortCut = q.getIntField(_T("lShortCut"));
  883. if (shortCut > 0)
  884. {
  885. clipData += _T(" | ");
  886. clipData += CHotKey::GetHotKeyDisplayStatic(shortCut);
  887. BOOL globalShortCut = q.getIntField(_T("globalShortCut"));
  888. if (globalShortCut)
  889. {
  890. clipData += _T(" - Global Shortcut Key");
  891. }
  892. }
  893. if (theApp.m_GroupID > 0)
  894. {
  895. int sticky = q.getIntField(_T("stickyClipGroupOrder"));
  896. if (sticky != INVALID_STICKY)
  897. {
  898. clipData += _T(" | ");
  899. clipData += _T(" - Sticky In Group");
  900. }
  901. }
  902. else
  903. {
  904. int sticky = q.getIntField(_T("stickyClipOrder"));
  905. if (sticky != INVALID_STICKY)
  906. {
  907. clipData += _T(" | ");
  908. clipData += _T(" - Sticky");
  909. }
  910. }
  911. m_pToolTip->SetClipData(clipData);
  912. }
  913. }
  914. CATCH_SQLITE_EXCEPTION
  915. Clip.m_cfType = CF_UNICODETEXT;
  916. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  917. {
  918. LPVOID pvData = GlobalLock(Clip.m_hgData);
  919. if(pvData)
  920. {
  921. CString csText = (WCHAR*)pvData;
  922. m_pToolTip->SetToolTipText(csText);
  923. bSetPlainText = true;
  924. }
  925. GlobalUnlock(Clip.m_hgData);
  926. Clip.Free();
  927. Clip.Clear();
  928. }
  929. if(bSetPlainText == false)
  930. {
  931. Clip.m_cfType = CF_TEXT;
  932. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  933. {
  934. LPVOID pvData = GlobalLock(Clip.m_hgData);
  935. if(pvData)
  936. {
  937. CString csText = (char*)pvData;
  938. m_pToolTip->SetToolTipText(csText);
  939. bSetPlainText = true;
  940. }
  941. GlobalUnlock(Clip.m_hgData);
  942. Clip.Free();
  943. Clip.Clear();
  944. }
  945. }
  946. if(bSetPlainText == false)
  947. {
  948. m_pToolTip->SetToolTipText(csDescription);
  949. }
  950. Clip.m_cfType = RegisterClipboardFormat(CF_RTF);
  951. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  952. {
  953. LPVOID pvData = GlobalLock(Clip.m_hgData);
  954. if(pvData)
  955. {
  956. m_pToolTip->SetRTFText((char*)pvData);
  957. }
  958. GlobalUnlock(Clip.m_hgData);
  959. Clip.Free();
  960. Clip.Clear();
  961. }
  962. Clip.m_cfType = CF_DIB;
  963. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  964. {
  965. m_pToolTip->SetGdiplusBitmap(Clip.CreateGdiplusBitmap());
  966. }
  967. else
  968. {
  969. Clip.m_cfType = theApp.m_PNG_Format;
  970. if (GetClipData(nItem, Clip) && Clip.m_hgData)
  971. {
  972. m_pToolTip->SetGdiplusBitmap(Clip.CreateGdiplusBitmap());
  973. }
  974. }
  975. m_pToolTip->Show(pt);
  976. }
  977. return true;
  978. }
  979. void CQListCtrl::GetToolTipText(int nItem, CString &csText)
  980. {
  981. CWnd* pParent=GetParent();
  982. if(pParent && (pParent->GetSafeHwnd() != NULL))
  983. {
  984. CQListToolTipText info;
  985. memset(&info, 0, sizeof(info));
  986. info.hdr.code = NM_GETTOOLTIPTEXT;
  987. info.hdr.hwndFrom = GetSafeHwnd();
  988. info.hdr.idFrom = GetDlgCtrlID();
  989. info.lItem = nItem;
  990. //plus 100 for extra info - shortcut and such
  991. info.cchTextMax = g_Opt.m_bDescTextSize + 100;
  992. info.pszText = csText.GetBufferSetLength(info.cchTextMax);
  993. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  994. csText.ReleaseBuffer();
  995. }
  996. }
  997. BOOL CQListCtrl::GetClipData(int nItem, CClipFormat &Clip)
  998. {
  999. return theApp.GetClipData(GetItemData(nItem), Clip);
  1000. }
  1001. DWORD CQListCtrl::GetItemData(int nItem)
  1002. {
  1003. if((GetStyle() & LVS_OWNERDATA))
  1004. {
  1005. CWnd* pParent=GetParent();
  1006. if(pParent && (pParent->GetSafeHwnd() != NULL))
  1007. {
  1008. LV_DISPINFO info;
  1009. memset(&info, 0, sizeof(info));
  1010. info.hdr.code = LVN_GETDISPINFO;
  1011. info.hdr.hwndFrom = GetSafeHwnd();
  1012. info.hdr.idFrom = GetDlgCtrlID();
  1013. info.item.iItem = nItem;
  1014. info.item.lParam = -1;
  1015. info.item.mask = LVIF_PARAM;
  1016. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  1017. return (DWORD)info.item.lParam;
  1018. }
  1019. }
  1020. return (DWORD)CListCtrl::GetItemData(nItem);
  1021. }
  1022. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_DIB_ClipFormat(int nItem)
  1023. {
  1024. CClipFormatQListCtrl *format = NULL;
  1025. CWnd* pParent=GetParent();
  1026. if(pParent && (pParent->GetSafeHwnd() != NULL))
  1027. {
  1028. LV_DISPINFO info;
  1029. memset(&info, 0, sizeof(info));
  1030. info.hdr.code = LVN_GETDISPINFO;
  1031. info.hdr.hwndFrom = GetSafeHwnd();
  1032. info.hdr.idFrom = GetDlgCtrlID();
  1033. info.item.iItem = nItem;
  1034. info.item.lParam = NULL;
  1035. info.item.mask = LVIF_CF_DIB;
  1036. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  1037. if(info.item.lParam != NULL)
  1038. {
  1039. format = (CClipFormatQListCtrl *)info.item.lParam;
  1040. }
  1041. }
  1042. return format;
  1043. }
  1044. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_RTF_ClipFormat(int nItem)
  1045. {
  1046. CClipFormatQListCtrl *format = NULL;
  1047. CWnd* pParent=GetParent();
  1048. if(pParent && (pParent->GetSafeHwnd() != NULL))
  1049. {
  1050. LV_DISPINFO info;
  1051. memset(&info, 0, sizeof(info));
  1052. info.hdr.code = LVN_GETDISPINFO;
  1053. info.hdr.hwndFrom = GetSafeHwnd();
  1054. info.hdr.idFrom = GetDlgCtrlID();
  1055. info.item.iItem = nItem;
  1056. info.item.lParam = NULL;
  1057. info.item.mask = LVIF_CF_RICHTEXT;
  1058. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  1059. if(info.item.lParam != NULL)
  1060. {
  1061. format = (CClipFormatQListCtrl *)info.item.lParam;
  1062. }
  1063. }
  1064. return format;
  1065. }
  1066. void CQListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1067. {
  1068. CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
  1069. }
  1070. void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate, CppSQLite3DB &db)
  1071. {
  1072. m_Accels.RemoveAll();
  1073. if(bCreate)
  1074. {
  1075. CMainTableFunctions::LoadAcceleratorKeys(m_Accels, db);
  1076. LoadDittoCopyBufferHotkeys();
  1077. }
  1078. }
  1079. void CQListCtrl::LoadDittoCopyBufferHotkeys()
  1080. {
  1081. CCopyBufferItem Item;
  1082. CAccel a;
  1083. g_Opt.GetCopyBufferItem(0, Item);
  1084. if(Item.m_lCopyHotKey > 0)
  1085. {
  1086. a.Cmd = COPY_BUFFER_HOT_KEY_1_ID;
  1087. a.Key = Item.m_lCopyHotKey;
  1088. m_Accels.AddAccel(a);
  1089. }
  1090. g_Opt.GetCopyBufferItem(1, Item);
  1091. if(Item.m_lCopyHotKey > 0)
  1092. {
  1093. a.Cmd = COPY_BUFFER_HOT_KEY_2_ID;
  1094. a.Key = Item.m_lCopyHotKey;
  1095. m_Accels.AddAccel(a);
  1096. }
  1097. g_Opt.GetCopyBufferItem(2, Item);
  1098. if(Item.m_lCopyHotKey > 0)
  1099. {
  1100. a.Cmd = COPY_BUFFER_HOT_KEY_3_ID;
  1101. a.Key = Item.m_lCopyHotKey;
  1102. m_Accels.AddAccel(a);
  1103. }
  1104. }
  1105. void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
  1106. {
  1107. CListCtrl::OnKillFocus(pNewWnd);
  1108. //if(FocusOnToolTip() == FALSE)
  1109. //m_pToolTip->Hide();
  1110. }
  1111. HWND CQListCtrl::GetToolTipHWnd()
  1112. {
  1113. if(VALID_TOOLTIP)
  1114. return m_pToolTip->GetSafeHwnd();
  1115. return NULL;
  1116. }
  1117. BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = 0 */)
  1118. {
  1119. return CListCtrl::SetItemCountEx(iCount, dwFlags);
  1120. }
  1121. void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
  1122. {
  1123. NMLISTVIEW *pnmv = (NMLISTVIEW *) pNMHDR;
  1124. if((pnmv->uNewState == 3) ||
  1125. (pnmv->uNewState == 1))
  1126. {
  1127. if (VALID_TOOLTIP &&
  1128. ::IsWindowVisible(m_pToolTip->m_hWnd))
  1129. {
  1130. this->ShowFullDescription(false, true);
  1131. }
  1132. if(g_Opt.m_bAllwaysShowDescription)
  1133. {
  1134. KillTimer(TIMER_SHOW_PROPERTIES);
  1135. SetTimer(TIMER_SHOW_PROPERTIES, 300, NULL);
  1136. }
  1137. if(GetSelectedCount() > 0 )
  1138. theApp.SetStatus(NULL, FALSE);
  1139. }
  1140. if(GetSelectedCount() == this->GetItemCount())
  1141. {
  1142. if(m_allSelected == false)
  1143. {
  1144. Log(StrF(_T("List box Select All")));
  1145. GetParent()->SendMessage(NM_ALL_SELECTED, 0, 0);
  1146. m_allSelected = true;
  1147. }
  1148. }
  1149. else if(m_allSelected == true)
  1150. {
  1151. Log(StrF(_T("List box REMOVED Select All")));
  1152. m_allSelected = false;
  1153. }
  1154. }
  1155. void CQListCtrl::OnTimer(UINT_PTR nIDEvent)
  1156. {
  1157. //http://support.microsoft.com/kb/200054
  1158. //OnTimer() Is Not Called Repeatedly for a List Control
  1159. bool callBase = true;
  1160. switch(nIDEvent)
  1161. {
  1162. case TIMER_SHOW_PROPERTIES:
  1163. {
  1164. if( theApp.m_bShowingQuickPaste )
  1165. ShowFullDescription(true);
  1166. KillTimer(TIMER_SHOW_PROPERTIES);
  1167. callBase = false;
  1168. }
  1169. break;
  1170. case TIMER_HIDE_SCROL:
  1171. {
  1172. CPoint cursorPos;
  1173. GetCursorPos(&cursorPos);
  1174. CRect crWindow;
  1175. this->GetWindowRect(&crWindow);
  1176. //check and see if they moved out of the scroll area
  1177. //If they did tell our parent so
  1178. if(MouseInScrollBarArea(crWindow, cursorPos) == false)
  1179. {
  1180. StopHideScrollBarTimer();
  1181. }
  1182. callBase = false;
  1183. }
  1184. break;
  1185. case TIMER_SHOW_SCROLL:
  1186. {
  1187. CPoint cursorPos;
  1188. GetCursorPos(&cursorPos);
  1189. CRect crWindow;
  1190. this->GetWindowRect(&crWindow);
  1191. //Adjust for the v-scroll bar being off of the screen
  1192. crWindow.right -= theApp.m_metrics.ScaleX(GetSystemMetrics(SM_CXVSCROLL));
  1193. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1194. //Check and see if we are still in the cursor area
  1195. if(MouseInScrollBarArea(crWindow, cursorPos))
  1196. {
  1197. m_timerToHideScrollAreaSet = true;
  1198. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);
  1199. //Start looking to hide the scroll bars
  1200. SetTimer(TIMER_HIDE_SCROL, 1000, NULL);
  1201. }
  1202. KillTimer(TIMER_SHOW_SCROLL);
  1203. callBase = false;
  1204. }
  1205. break;
  1206. }
  1207. if(callBase)
  1208. {
  1209. CListCtrl::OnTimer(nIDEvent);
  1210. }
  1211. }
  1212. void CQListCtrl::SetLogFont(LOGFONT &font)
  1213. {
  1214. m_Font.DeleteObject();
  1215. m_boldFont.DeleteObject();
  1216. m_Font.CreateFontIndirect(&font);
  1217. font.lfWeight = 600;
  1218. m_boldFont.CreateFontIndirect(&font);
  1219. SetFont(&m_Font);
  1220. }
  1221. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1222. {
  1223. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  1224. }
  1225. BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  1226. {
  1227. NMLVCACHEHINT* pcachehint = NULL;
  1228. if(message == WM_NOTIFY)
  1229. {
  1230. NMHDR* phdr = (NMHDR*)lParam;
  1231. switch(phdr->code)
  1232. {
  1233. case LVN_ODCACHEHINT:
  1234. pcachehint= (NMLVCACHEHINT*) phdr;
  1235. GetParent()->SendMessage(NM_FILL_REST_OF_LIST, pcachehint->iFrom, pcachehint->iTo);
  1236. return FALSE;
  1237. }
  1238. }
  1239. return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
  1240. }
  1241. BOOL CQListCtrl::OnItemDeleted(long lID)
  1242. {
  1243. BOOL bRet2 = m_RTFData.RemoveKey(lID);
  1244. return (bRet2);
  1245. }
  1246. void CQListCtrl::OnMouseMove(UINT nFlags, CPoint point)
  1247. {
  1248. if(g_Opt.m_showScrollBar == FALSE)
  1249. {
  1250. CPoint cursorPos;
  1251. GetCursorPos(&cursorPos);
  1252. CRect crWindow;
  1253. this->GetWindowRect(&crWindow);
  1254. ScreenToClient(&crWindow);
  1255. crWindow.right -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1256. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1257. if(MouseInScrollBarArea(crWindow, point))
  1258. {
  1259. if((GetTickCount() - m_mouseOverScrollAreaStart) > 500)
  1260. {
  1261. SetTimer(TIMER_SHOW_SCROLL, 500, NULL);
  1262. m_mouseOverScrollAreaStart = GetTickCount();
  1263. }
  1264. }
  1265. else
  1266. {
  1267. if(m_timerToHideScrollAreaSet)
  1268. {
  1269. StopHideScrollBarTimer();
  1270. }
  1271. KillTimer(TIMER_SHOW_SCROLL);
  1272. }
  1273. }
  1274. CListCtrl::OnMouseMove(nFlags, point);
  1275. }
  1276. bool CQListCtrl::MouseInScrollBarArea(CRect crWindow, CPoint point)
  1277. {
  1278. CRect crRight(crWindow);
  1279. CRect crBottom(crWindow);
  1280. crRight.left = crRight.right - theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1281. crBottom.top = crBottom.bottom - theApp.m_metrics.ScaleY(::GetSystemMetrics(SM_CYHSCROLL));
  1282. /*CString cs;
  1283. cs.Format(_T("point.x: %d, Width: %d, Height: %d\n"), point.x, crWindow.Width(), crWindow.Height());
  1284. OutputDebugString(cs);*/
  1285. if(crRight.PtInRect(point) || crBottom.PtInRect(point))
  1286. {
  1287. return true;
  1288. }
  1289. return false;
  1290. }
  1291. void CQListCtrl::StopHideScrollBarTimer()
  1292. {
  1293. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
  1294. m_timerToHideScrollAreaSet = false;
  1295. KillTimer(TIMER_HIDE_SCROL);
  1296. }
  1297. void CQListCtrl::SetSearchText(CString text)
  1298. {
  1299. m_searchText = text;
  1300. }
  1301. void CQListCtrl::HidePopup(bool checkShowPersistant)
  1302. {
  1303. if (VALID_TOOLTIP)
  1304. {
  1305. if (checkShowPersistant == false ||
  1306. m_pToolTip->GetShowPersistant() == false)
  1307. {
  1308. m_pToolTip->Hide();
  1309. }
  1310. }
  1311. }
  1312. BOOL CQListCtrl::IsToolTipWindowVisible()
  1313. {
  1314. if (VALID_TOOLTIP)
  1315. {
  1316. return ::IsWindowVisible(m_toolTipHwnd);
  1317. }
  1318. return FALSE;
  1319. }
  1320. void CQListCtrl::ToggleToolTipShowPersistant()
  1321. {
  1322. if (VALID_TOOLTIP)
  1323. {
  1324. m_pToolTip->ToggleShowPersistant();
  1325. }
  1326. }
  1327. bool CQListCtrl::ToggleToolTipWordWrap()
  1328. {
  1329. bool didWordWrap = false;
  1330. if (VALID_TOOLTIP)
  1331. {
  1332. didWordWrap = m_pToolTip->ToggleWordWrap();
  1333. }
  1334. return didWordWrap;
  1335. }
  1336. BOOL CQListCtrl::IsToolTipWindowFocus()
  1337. {
  1338. if (VALID_TOOLTIP)
  1339. {
  1340. return ::GetFocus() == m_toolTipHwnd ||
  1341. ::GetParent(::GetFocus()) == m_toolTipHwnd;
  1342. }
  1343. return FALSE;
  1344. }
  1345. bool CQListCtrl::IsToolTipShowPersistant()
  1346. {
  1347. if (VALID_TOOLTIP)
  1348. {
  1349. return m_pToolTip->GetShowPersistant();
  1350. }
  1351. return false;
  1352. }
  1353. void CQListCtrl::DoToolTipSearch()
  1354. {
  1355. if (VALID_TOOLTIP)
  1356. {
  1357. return m_pToolTip->DoSearch();
  1358. }
  1359. }
  1360. void CQListCtrl::HideToolTip()
  1361. {
  1362. if (VALID_TOOLTIP)
  1363. {
  1364. m_pToolTip->Hide();
  1365. }
  1366. }