QListCtrl.cpp 39 KB

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