QListCtrl.cpp 39 KB

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