XTPScrollBar.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:34k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTPScrollBar.cpp : implementation of the CXTPScrollBar class.
  2. //
  3. // This file is a part of the XTREME COMMANDBARS MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Common/XTPDrawHelpers.h"
  22. #include "XTPCommandBars.h"
  23. #include "XTPPaintManager.h"
  24. #include "XTPScrollBar.h"
  25. #include "XTPMouseManager.h"
  26. #define IDSYS_SCROLL 23345
  27. #define IDSYS_ANIMATE 23346
  28. //////////////////////////////////////////////////////////////////////////
  29. //  CXTPScrollBase
  30. CXTPScrollBase::SLIDERTICKS::SLIDERTICKS(double* pTicks, int nCount)
  31. {
  32. this->nCount = nCount;
  33. this->pTicks = new double[nCount];
  34. for (int i = 0; i < nCount; i++)
  35. this->pTicks[i] = pTicks[i];
  36. }
  37. CXTPScrollBase::SLIDERTICKS::~SLIDERTICKS()
  38. {
  39. SAFE_DELETE(pTicks);
  40. }
  41. CXTPScrollBase::CXTPScrollBase()
  42. {
  43. ZeroMemory(&m_spi, sizeof(m_spi));
  44. m_spi.fVert = TRUE;
  45. m_pSBTrack = NULL;
  46. m_scrollBarStyle = xtpScrollStyleDefault;
  47. m_bAnimation = FALSE;
  48. m_nTimerElapse = 0;
  49. m_pTicks = NULL;
  50. }
  51. CXTPScrollBase::~CXTPScrollBase()
  52. {
  53. SAFE_DELETE(m_pTicks);
  54. }
  55. void CXTPScrollBase::CalcScrollBarInfo(LPRECT lprc, SCROLLBARPOSINFO* pSBInfo, SCROLLINFO* pSI)
  56. {
  57. int cpx;
  58. DWORD dwRange;
  59. int denom;
  60. BOOL fVert = pSBInfo->fVert;
  61. pSBInfo->rc = *lprc;
  62. pSBInfo->pxPopup = 0;
  63. CXTPScrollBarPaintManager* pPaintManager = GetScrollBarPaintManager();
  64. if (fVert)
  65. {
  66. pSBInfo->pxTop = lprc->top;
  67. pSBInfo->pxBottom = lprc->bottom;
  68. pSBInfo->pxLeft = lprc->left;
  69. pSBInfo->pxRight = lprc->right;
  70. pSBInfo->cpxThumb = pPaintManager->m_cyVScroll;
  71. }
  72. else
  73. {
  74. pSBInfo->pxTop = lprc->left;
  75. pSBInfo->pxBottom = lprc->right;
  76. pSBInfo->pxLeft = lprc->top;
  77. pSBInfo->pxRight = lprc->bottom;
  78. pSBInfo->cpxThumb = pPaintManager->m_cxHScroll;
  79. }
  80. pSBInfo->pos = pSI->nPos;
  81. pSBInfo->page = pSI->nPage;
  82. pSBInfo->posMin = pSI->nMin;
  83. pSBInfo->posMax = pSI->nMax;
  84. dwRange = ((DWORD)(pSBInfo->posMax - pSBInfo->posMin)) + 1;
  85. cpx = min((pSBInfo->pxBottom - pSBInfo->pxTop) / 2, pSBInfo->cpxThumb);
  86. pSBInfo->pxUpArrow  = pSBInfo->pxTop    + cpx;
  87. pSBInfo->pxDownArrow = pSBInfo->pxBottom - cpx;
  88. if ((pSBInfo->page != 0) && (dwRange != 0))
  89. {
  90. int i = MulDiv(pSBInfo->pxDownArrow - pSBInfo->pxUpArrow,
  91. pSBInfo->page, dwRange);
  92. pSBInfo->cpxThumb = max(pSBInfo->cpxThumb / 2, i);
  93. }
  94. if (pPaintManager->m_cThumb > 0) pSBInfo->cpxThumb = pPaintManager->m_cThumb;
  95. pSBInfo->pxMin = pSBInfo->pxTop + cpx;
  96. pSBInfo->cpx = pSBInfo->pxBottom - cpx - pSBInfo->cpxThumb - pSBInfo->pxMin;
  97. denom = dwRange - (pSBInfo->page ? pSBInfo->page : 1);
  98. if (denom)
  99. pSBInfo->pxThumbTop = MulDiv(pSBInfo->pos - pSBInfo->posMin,
  100. pSBInfo->cpx, denom) + pSBInfo->pxMin;
  101. else
  102. pSBInfo->pxThumbTop = pSBInfo->pxMin - 1;
  103. pSBInfo->pxThumbBottom = pSBInfo->pxThumbTop + pSBInfo->cpxThumb;
  104. }
  105. void CXTPScrollBase::SetupScrollInfo()
  106. {
  107. CRect rc = GetScrollBarRect();
  108. SCROLLINFO si;
  109. GetScrollInfo(&si);
  110. CalcScrollBarInfo(&rc, &m_spi, &si);
  111. }
  112. CRect CXTPScrollBase::GetScrollBarPartRect(int nPart) const
  113. {
  114. CRect rc(m_spi.rc);
  115. switch (nPart)
  116. {
  117. case XTP_HTSCROLLUP: return m_spi.fVert ? CRect(rc.left, rc.top, rc.right, rc.top + m_spi.pxUpArrow) : CRect(rc.left, rc.top, rc.left + m_spi.pxUpArrow, rc.bottom);
  118. case XTP_HTSCROLLDOWN: return m_spi.fVert ? CRect(rc.left, rc.bottom - m_spi.pxDownArrow, rc.right, rc.bottom) : CRect(rc.right - m_spi.pxDownArrow, rc.top, rc.right, rc.bottom);
  119. case XTP_HTSCROLLUPPAGE: return m_spi.fVert ? CRect(rc.left, rc.top + m_spi.pxUpArrow, rc.right, rc.top + m_spi.pxThumbTop) : CRect(rc.left + m_spi.pxUpArrow, rc.top, rc.left + m_spi.pxThumbTop, rc.bottom);
  120. case XTP_HTSCROLLDOWNPAGE: return m_spi.fVert ? CRect(rc.left, rc.top + m_spi.pxThumbBottom, rc.right, rc.top + m_spi.pxDownArrow) : CRect(rc.left + m_spi.pxThumbBottom, rc.top, rc.left + m_spi.pxDownArrow, rc.bottom);
  121. case XTP_HTSCROLLTHUMB: return m_spi.fVert ? CRect(rc.left, rc.top + m_spi.pxThumbTop, rc.right, rc.top + m_spi.pxThumbBottom) : CRect(rc.left + m_spi.pxThumbTop, rc.top, rc.left + m_spi.pxThumbBottom, rc.bottom);
  122. }
  123. return rc;
  124. }
  125. int CXTPScrollBase::HitTestScrollBar(POINT pt) const
  126. {
  127. int px = m_spi.fVert ? pt.y : pt.x;
  128. if (!::PtInRect(&m_spi.rc, pt))
  129. return HTNOWHERE;
  130. if (px < m_spi.pxUpArrow)
  131. return XTP_HTSCROLLUP;
  132. if (m_spi.pxPopup > 0 && px > m_spi.pxPopup)
  133. return XTP_HTSCROLLPOPUP;
  134. if (px >= m_spi.pxDownArrow)
  135. return XTP_HTSCROLLDOWN;
  136. if (px < m_spi.pxThumbTop)
  137. return XTP_HTSCROLLUPPAGE;
  138. if (px < m_spi.pxThumbBottom)
  139. return XTP_HTSCROLLTHUMB;
  140. if (px < m_spi.pxDownArrow)
  141. return XTP_HTSCROLLDOWNPAGE;
  142. return HTERROR;
  143. }
  144. //////////////////////////////////////////////////////////////////////////
  145. // Scrolling
  146. void CXTPScrollBase::EndScroll(BOOL fCancel)
  147. {
  148. SCROLLBARTRACKINFO* pSBTrack = m_pSBTrack;
  149. if (pSBTrack)
  150. {
  151. pSBTrack->cmdSB = 0;
  152. ReleaseCapture();
  153. if (pSBTrack->bTrackThumb)
  154. {
  155. if (fCancel)
  156. {
  157. pSBTrack->posOld = pSBTrack->pSBInfo->pos;
  158. }
  159. DoScroll(SB_THUMBPOSITION, pSBTrack->posOld);
  160. RedrawScrollBar();
  161. }
  162. else
  163. {
  164. if (pSBTrack->hTimerSB != 0)
  165. {
  166. ::KillTimer(pSBTrack->hWndTrack, pSBTrack->hTimerSB);
  167. pSBTrack->hTimerSB = 0;
  168. }
  169. }
  170. DoScroll(SB_ENDSCROLL, 0);
  171. }
  172. }
  173. AFX_INLINE int SBPosFromPx(CXTPScrollBase::SCROLLBARPOSINFO*  pSBInfo, int px)
  174. {
  175. if (px < pSBInfo->pxMin)
  176. {
  177. return pSBInfo->posMin;
  178. }
  179. if (px >= pSBInfo->pxMin + pSBInfo->cpx)
  180. {
  181. return (pSBInfo->posMax - (pSBInfo->page ? pSBInfo->page - 1 : 0));
  182. }
  183. if (pSBInfo->cpx)
  184. return (pSBInfo->posMin + MulDiv(pSBInfo->posMax - pSBInfo->posMin -
  185. (pSBInfo->page ? pSBInfo->page - 1 : 0),
  186. px - pSBInfo->pxMin, pSBInfo->cpx));
  187. else
  188. return (pSBInfo->posMin - 1);
  189. }
  190. void CXTPScrollBase::MoveThumb(int px)
  191. {
  192. SCROLLBARTRACKINFO* pSBTrack = m_pSBTrack;
  193. if ((pSBTrack == NULL) || (px == pSBTrack->pxOld))
  194. return;
  195. SCROLLBARPOSINFO* pSBInfo = m_pSBTrack->pSBInfo;
  196. pxReCalc:
  197. pSBTrack->posNew = SBPosFromPx(pSBInfo, px);
  198. if (pSBTrack->posNew != pSBTrack->posOld)
  199. {
  200. DoScroll(SB_THUMBTRACK, pSBTrack->posNew);
  201. pSBTrack->posOld = pSBTrack->posNew;
  202. if (px >= pSBInfo->pxMin + pSBInfo->cpx)
  203. {
  204. px = pSBInfo->pxMin + pSBInfo->cpx;
  205. goto pxReCalc;
  206. }
  207. }
  208. pSBInfo->pxThumbTop = px;
  209. pSBInfo->pxThumbBottom = pSBInfo->pxThumbTop + pSBInfo->cpxThumb;
  210. pSBTrack->pxOld = px;
  211. RedrawScrollBar();
  212. }
  213. void CXTPScrollBase::TrackThumb(UINT message, CPoint pt)
  214. {
  215. SCROLLBARTRACKINFO* pSBTrack = m_pSBTrack;
  216. if (!pSBTrack)
  217. return;
  218. SCROLLBARPOSINFO* pSBInfo = pSBTrack->pSBInfo;
  219. if (HIBYTE(message) != HIBYTE(WM_MOUSEFIRST))
  220. return;
  221. if (pSBInfo == NULL)
  222. return;
  223. int px;
  224. if (!PtInRect(&pSBTrack->rcTrack, pt) && (GetScrollBarPaintManager()->m_cThumb == 0))
  225. px = pSBInfo->pxStart;
  226. else
  227. {
  228. px = (pSBTrack->pSBInfo->fVert ? pt.y : pt.x) + pSBTrack->dpxThumb;
  229. if (px < pSBInfo->pxMin)
  230. px = pSBInfo->pxMin;
  231. else if (px >= pSBInfo->pxMin + pSBInfo->cpx)
  232. px = pSBInfo->pxMin + pSBInfo->cpx;
  233. }
  234. MoveThumb(px);
  235. if (message == WM_LBUTTONUP || GetKeyState(VK_LBUTTON) >= 0)
  236. {
  237. EndScroll(FALSE);
  238. }
  239. }
  240. void CXTPScrollBase::TrackBox(UINT message, CPoint point)
  241. {
  242. SCROLLBARTRACKINFO* pSBTrack = m_pSBTrack;
  243. if (pSBTrack == NULL)
  244. return;
  245. if (message != WM_NULL && HIBYTE(message) != HIBYTE(WM_MOUSEFIRST))
  246. return;
  247. if ((pSBTrack->cmdSB == SB_PAGEUP || pSBTrack->cmdSB == SB_PAGEDOWN))
  248. {
  249. int* pLength = (int *)&pSBTrack->rcTrack;
  250. if (pSBTrack->pSBInfo->fVert)
  251. pLength++;
  252. if (pSBTrack->cmdSB == SB_PAGEUP)
  253. pLength[2] = pSBTrack->pSBInfo->pxThumbTop;
  254. else
  255. pLength[0] = pSBTrack->pSBInfo->pxThumbBottom;
  256. }
  257. BOOL fHit = PtInRect(&pSBTrack->rcTrack, point);
  258. BOOL fHitChanged = fHit != (BOOL)pSBTrack->fHitOld;
  259. if (fHitChanged)
  260. {
  261. pSBTrack->fHitOld = fHit;
  262. RedrawScrollBar();
  263. }
  264. int cmsTimer = GetDoubleClickTime() / 10;
  265. switch (message)
  266. {
  267. case WM_LBUTTONUP:
  268. EndScroll(FALSE);
  269. break;
  270. case WM_LBUTTONDOWN:
  271. pSBTrack->hTimerSB = 0;
  272. cmsTimer = GetDoubleClickTime() * 4 / 5;
  273. /*
  274. *** FALL THRU **
  275. */
  276. case WM_MOUSEMOVE:
  277. if (fHit && fHitChanged)
  278. {
  279. pSBTrack->hTimerSB = SetTimer(m_pSBTrack->hWndTrack, IDSYS_SCROLL, m_nTimerElapse = cmsTimer, NULL);
  280. DoScroll(pSBTrack->cmdSB, 0);
  281. }
  282. }
  283. }
  284. void CXTPScrollBase::DoAnimate()
  285. {
  286. }
  287. void CXTPScrollBase::ContScroll()
  288. {
  289. SCROLLBARTRACKINFO* pSBTrack = m_pSBTrack;
  290. ASSERT(pSBTrack);
  291. if (pSBTrack == NULL)
  292. return;
  293. CPoint pt;
  294. GetCursorPos(&pt);
  295. ScreenToClient(m_pSBTrack->hWndTrack, &pt);
  296. TrackBox(WM_NULL, pt);
  297. if (pSBTrack->fHitOld)
  298. {
  299. pSBTrack->hTimerSB = SetTimer(m_pSBTrack->hWndTrack, IDSYS_SCROLL, m_nTimerElapse = GetDoubleClickTime() / 10, NULL);
  300. DoScroll(pSBTrack->cmdSB, 0);
  301. }
  302. }
  303. void CXTPScrollBase::CalcTrackDragRect(SCROLLBARTRACKINFO* pSBTrack) const
  304. {
  305. int     cx;
  306. int     cy;
  307. LPINT   pwX, pwY;
  308. pwX = pwY = (LPINT)&pSBTrack->rcTrack;
  309. if (pSBTrack->pSBInfo->fVert)
  310. {
  311. cy = GetSystemMetrics(SM_CYVTHUMB);
  312. pwY++;
  313. }
  314. else
  315. {
  316. cy = GetSystemMetrics(SM_CXHTHUMB);
  317. pwX++;
  318. }
  319. cx = (pSBTrack->pSBInfo->pxRight - pSBTrack->pSBInfo->pxLeft) * 8;
  320. cy *= 2;
  321. *(pwX + 0) = pSBTrack->pSBInfo->pxLeft - cx;
  322. *(pwY + 0) = pSBTrack->pSBInfo->pxTop - cy;
  323. *(pwX + 2) = pSBTrack->pSBInfo->pxRight + cx;
  324. *(pwY + 2) = pSBTrack->pSBInfo->pxBottom + cy;
  325. }
  326. void CXTPScrollBase::PerformTrackInit(HWND hWnd, CPoint point, SCROLLBARPOSINFO* pSBInfo, BOOL bDirect)
  327. {
  328. int px = m_spi.fVert ? point.y : point.x;
  329. SCROLLBARTRACKINFO* pSBTrack = new SCROLLBARTRACKINFO;
  330. memset(pSBTrack, 0, sizeof(SCROLLBARTRACKINFO));
  331. pSBTrack->cmdSB = (UINT)-1;
  332. pSBTrack->bTrackThumb = FALSE;
  333. pSBTrack->pSBInfo = pSBInfo;
  334. pSBTrack->hWndTrack = hWnd;
  335. m_pSBTrack = pSBTrack;
  336. CXTPMouseManager* pMouseManager = XTPMouseManager();
  337. RECT rcSB;
  338. LPINT pwX = (LPINT)&rcSB;
  339. LPINT pwY = pwX + 1;
  340. if (!pSBInfo->fVert)
  341. pwX = pwY--;
  342. *(pwX + 0) = pSBInfo->pxLeft;
  343. *(pwY + 0) = pSBInfo->pxTop;
  344. *(pwX + 2) = pSBInfo->pxRight;
  345. *(pwY + 2) = pSBInfo->pxBottom;
  346. if (px < pSBInfo->pxUpArrow)
  347. {
  348. pSBInfo->ht = XTP_HTSCROLLUP;
  349. pSBTrack->cmdSB = SB_LINEUP;
  350. *(pwY + 2) = pSBInfo->pxUpArrow;
  351. }
  352. else if (px >= pSBInfo->pxDownArrow)
  353. {
  354. pSBInfo->ht = XTP_HTSCROLLDOWN;
  355. pSBTrack->cmdSB = SB_LINEDOWN;
  356. *(pwY + 0) = pSBInfo->pxDownArrow;
  357. }
  358. else if (px < pSBInfo->pxThumbTop)
  359. {
  360. pSBInfo->ht = XTP_HTSCROLLUPPAGE;
  361. pSBTrack->cmdSB = SB_PAGEUP;
  362. *(pwY + 0) = pSBInfo->pxUpArrow;
  363. *(pwY + 2) = pSBInfo->pxThumbTop;
  364. }
  365. else if (px < pSBInfo->pxThumbBottom)
  366. {
  367. pSBInfo->ht = XTP_HTSCROLLTHUMB;
  368. DoThumbPos:
  369. if (pSBInfo->pxDownArrow - pSBInfo->pxUpArrow <= pSBInfo->cpxThumb)
  370. {
  371. delete m_pSBTrack;
  372. m_pSBTrack = NULL;
  373. return;
  374. }
  375. pSBTrack->cmdSB = SB_THUMBPOSITION;
  376. CalcTrackDragRect(pSBTrack);
  377. pSBTrack->pxOld = pSBInfo->pxStart = pSBInfo->pxThumbTop;
  378. pSBTrack->posNew = pSBTrack->posOld = pSBInfo->pos;
  379. pSBTrack->dpxThumb = pSBInfo->pxStart - px;
  380. pSBTrack->bTrackThumb = TRUE;
  381. ::SetCapture(hWnd);
  382. DoScroll(SB_THUMBTRACK, pSBTrack->posOld);
  383. }
  384. else if (px < pSBInfo->pxDownArrow)
  385. {
  386. pSBInfo->ht = XTP_HTSCROLLDOWNPAGE;
  387. pSBTrack->cmdSB = SB_PAGEDOWN;
  388. *(pwY + 0) = pSBInfo->pxThumbBottom;
  389. *(pwY + 2) = pSBInfo->pxDownArrow;
  390. }
  391. if ((bDirect && pSBTrack->cmdSB != SB_LINEUP && pSBTrack->cmdSB != SB_LINEDOWN))
  392. {
  393. if (pSBTrack->cmdSB != SB_THUMBPOSITION)
  394. {
  395. goto DoThumbPos;
  396. }
  397. pSBTrack->dpxThumb = -(pSBInfo->cpxThumb / 2);
  398. }
  399. ::SetCapture(hWnd);
  400. if (pSBTrack->cmdSB != SB_THUMBPOSITION)
  401. {
  402. CopyRect(&pSBTrack->rcTrack, &rcSB);
  403. }
  404. if (!pSBTrack->bTrackThumb)
  405. {
  406. TrackBox(WM_LBUTTONDOWN, point);
  407. }
  408. else
  409. {
  410. TrackThumb(WM_LBUTTONDOWN, point);
  411. RedrawScrollBar();
  412. }
  413. pMouseManager->LockMouseMove();
  414. while (::GetCapture() == hWnd)
  415. {
  416. MSG msg;
  417. if (!::GetMessage(&msg, NULL, 0, 0))
  418. {
  419. AfxPostQuitMessage((int)msg.wParam);
  420. break;
  421. }
  422. if (!IsWindow(hWnd))
  423. break;
  424. UINT cmd = msg.message;
  425. if (cmd == WM_TIMER && msg.wParam == IDSYS_SCROLL)
  426. {
  427. ContScroll();
  428. }
  429. else if (cmd == WM_TIMER && msg.wParam == IDSYS_ANIMATE)
  430. {
  431. DoAnimate();
  432. }
  433. else if (cmd >= WM_MOUSEFIRST && cmd <= WM_MOUSELAST)
  434. {
  435. CPoint ptScreen = msg.pt;
  436. ScreenToClient(hWnd, &ptScreen);
  437. if (!pSBTrack->bTrackThumb)
  438. {
  439. TrackBox(cmd, ptScreen);
  440. }
  441. else
  442. {
  443. TrackThumb(cmd, ptScreen);
  444. }
  445. }
  446. else
  447. {
  448. TranslateMessage(&msg);
  449. DispatchMessage(&msg);
  450. }
  451. }
  452. pMouseManager->UnlockMouseMove();
  453. if (pSBTrack->hTimerSB != 0)
  454. {
  455. ::KillTimer(hWnd, pSBTrack->hTimerSB);
  456. }
  457. delete m_pSBTrack;
  458. m_pSBTrack = NULL;
  459. if (IsWindow(hWnd))
  460. {
  461. GetCursorPos(&point);
  462. ScreenToClient(hWnd, &point);
  463. m_spi.ht = HitTestScrollBar(point);
  464. RedrawScrollBar();
  465. }
  466. while (IsWindow(hWnd) && m_bAnimation)
  467. {
  468. MSG msg;
  469. if (!::GetMessage(&msg, NULL, 0, 0))
  470. {
  471. AfxPostQuitMessage((int)msg.wParam);
  472. break;
  473. }
  474. UINT cmd = msg.message;
  475. if (cmd == WM_TIMER && msg.wParam == IDSYS_ANIMATE)
  476. {
  477. DoAnimate();
  478. }
  479. else
  480. {
  481. TranslateMessage(&msg);
  482. DispatchMessage(&msg);
  483. }
  484. }
  485. }
  486. XTPScrollBarStyle CXTPScrollBase::GetScrollBarStyle() const
  487. {
  488. if (m_scrollBarStyle != xtpScrollStyleDefault)
  489. return m_scrollBarStyle;
  490. switch (GetScrollBarPaintManager()->GetPaintManager()->BaseTheme())
  491. {
  492. case xtpThemeOffice2000:
  493. return xtpScrollStyleFlat;
  494. case xtpThemeOffice2007:
  495. case xtpThemeRibbon:
  496. return xtpScrollStyleOffice2007Light;
  497. }
  498. return xtpScrollStyleSystem;
  499. }
  500. //////////////////////////////////////////////////////////////////////////
  501. // CXTPScrollBar
  502. CXTPScrollBar::CXTPScrollBar()
  503. {
  504. m_pCommandBars = 0;
  505. }
  506. CXTPScrollBar::~CXTPScrollBar()
  507. {
  508. }
  509. BEGIN_MESSAGE_MAP(CXTPScrollBar, CScrollBar)
  510. //{{AFX_MSG_MAP(CXTPStatusBar)
  511. ON_WM_PAINT()
  512. ON_MESSAGE(WM_PRINTCLIENT, OnPrintClient)
  513. ON_WM_ENABLE()
  514. ON_WM_MOUSEMOVE()
  515. ON_MESSAGE_VOID(WM_MOUSELEAVE, OnMouseLeave)
  516. ON_WM_LBUTTONDOWN()
  517. ON_WM_LBUTTONDBLCLK()
  518. ON_MESSAGE(SBM_SETSCROLLINFO, OnSetScrollInfo)
  519. ON_MESSAGE(SBM_GETSCROLLINFO, OnGetScrollInfo)
  520. ON_WM_SETFOCUS()
  521. ON_WM_CONTEXTMENU()
  522. //}}AFX_MSG_MAP
  523. END_MESSAGE_MAP()
  524. CRect CXTPScrollBar::GetScrollBarRect()
  525. {
  526. return CXTPClientRect(this);
  527. }
  528. void CXTPScrollBar::GetScrollInfo(SCROLLINFO* psi)
  529. {
  530. psi->cbSize = sizeof(SCROLLINFO);
  531. psi->fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
  532. ::GetScrollInfo(m_hWnd, SB_CTL, psi);
  533. }
  534. BOOL CXTPScrollBar::IsScrollBarEnabled() const
  535. {
  536. return IsWindowEnabled();
  537. }
  538. CWnd* CXTPScrollBar::GetParentWindow() const
  539. {
  540. return GetParent();
  541. }
  542. CXTPScrollBarPaintManager* CXTPScrollBar::GetScrollBarPaintManager() const
  543. {
  544. if (m_pCommandBars)
  545. return (CXTPScrollBarPaintManager*)m_pCommandBars->GetPaintManager()->GetGalleryPaintManager();
  546. return (CXTPScrollBarPaintManager*)XTPPaintManager()->GetGalleryPaintManager();
  547. }
  548. void CXTPScrollBar::OnPaint()
  549. {
  550. CPaintDC dcPaint(this); // device context for painting
  551. CXTPBufferDC dc(dcPaint);
  552. OnDraw(&dc);
  553. }
  554. LRESULT CXTPScrollBar::OnPrintClient(WPARAM wParam, LPARAM /*lParam*/)
  555. {
  556. CDC* pDC = CDC::FromHandle((HDC)wParam);
  557. if (pDC) OnDraw(pDC);
  558. return 1;
  559. }
  560. void CXTPScrollBar::OnDraw(CDC* pDC)
  561. {
  562. DefWindowProc(WM_PAINT, (WPARAM)pDC->GetSafeHdc(), 0);
  563. m_spi.fVert = GetStyle() & SBS_VERT;
  564. if (!m_pSBTrack || !m_pSBTrack->bTrackThumb)
  565. SetupScrollInfo();
  566. GetScrollBarPaintManager()->DrawScrollBar(pDC, this);
  567. }
  568. void CXTPScrollBar::DoScroll(int cmd, int pos)
  569. {
  570. GetParent()->SendMessage((UINT)(m_spi.fVert ? WM_VSCROLL : WM_HSCROLL),
  571. MAKELONG(cmd, pos), (LPARAM)m_hWnd);
  572. }
  573. void CXTPScrollBar::RedrawScrollBar()
  574. {
  575. Invalidate(FALSE);
  576. }
  577. void CXTPScrollBar::OnEnable(BOOL bEnable)
  578. {
  579. CScrollBar::OnEnable(bEnable);
  580. Invalidate(FALSE);
  581. }
  582. void CXTPScrollBar::OnMouseLeave()
  583. {
  584. OnMouseMove(0, CPoint(-1, -1));
  585. }
  586. void CXTPScrollBar::OnMouseMove(UINT /*nFlags*/, CPoint point)
  587. {
  588. int ht = HitTestScrollBar(point);
  589. if (ht != m_spi.ht)
  590. {
  591. m_spi.ht = ht;
  592. Invalidate(FALSE);
  593. if (m_spi.ht != HTNOWHERE)
  594. {
  595. TRACKMOUSEEVENT tme = {sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd, HOVER_DEFAULT};
  596. _TrackMouseEvent(&tme);
  597. }
  598. }
  599. }
  600. void CXTPScrollBar::OnLButtonDown(UINT /*nFlags*/, CPoint point)
  601. {
  602. PerformTrackInit(m_hWnd, point, &m_spi, (GetKeyState(VK_SHIFT) < 0) ? TRUE : FALSE);
  603. }
  604. void CXTPScrollBar::OnContextMenu(CWnd* pWnd, CPoint pos)
  605. {
  606. CScrollBar::OnContextMenu(pWnd, pos);
  607. Invalidate(FALSE);
  608. }
  609. void CXTPScrollBar::OnLButtonDblClk(UINT nFlags, CPoint point)
  610. {
  611. OnLButtonDown(nFlags, point);
  612. }
  613. LRESULT CXTPScrollBar::OnSetScrollInfo(WPARAM wParam, LPARAM lParam)
  614. {
  615. LRESULT bResult = DefWindowProc(SBM_SETSCROLLINFO, FALSE, lParam);
  616. if (wParam)
  617. {
  618. Invalidate(FALSE);
  619. UpdateWindow();
  620. }
  621. return bResult;
  622. }
  623. LRESULT CXTPScrollBar::OnGetScrollInfo(WPARAM wParam, LPARAM lParam)
  624. {
  625. LRESULT bResult = DefWindowProc(SBM_GETSCROLLINFO, wParam, lParam);
  626. LPSCROLLINFO lpsi = (LPSCROLLINFO)lParam;
  627. if (lpsi && (lpsi->fMask & SIF_TRACKPOS) && m_pSBTrack)
  628. {
  629. lpsi->nTrackPos = m_pSBTrack->posNew;
  630. }
  631. return bResult;
  632. }
  633. void CXTPScrollBar::OnSetFocus(CWnd* pOldWnd)
  634. {
  635. pOldWnd;
  636. }
  637. //////////////////////////////////////////////////////////////////////////
  638. // CXTPScrollBarPaintManager
  639. CXTPScrollBarPaintManager::CXTPScrollBarPaintManager(CXTPPaintManager* pPaintManager)
  640. {
  641. m_pPaintManager = pPaintManager;
  642. m_cxHScroll = GetSystemMetrics(SM_CXHSCROLL);
  643. m_cyHScroll = GetSystemMetrics(SM_CYHSCROLL);
  644. m_cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
  645. m_cyVScroll = GetSystemMetrics(SM_CYVSCROLL);
  646. m_cThumb = 0;
  647. }
  648. CXTPScrollBarPaintManager::~CXTPScrollBarPaintManager()
  649. {
  650. }
  651. void CXTPScrollBarPaintManager::RefreshMetrics()
  652. {
  653. m_cxHScroll = GetSystemMetrics(SM_CXHSCROLL);
  654. m_cyHScroll = GetSystemMetrics(SM_CYHSCROLL);
  655. m_cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
  656. m_cyVScroll = GetSystemMetrics(SM_CYVSCROLL);
  657. m_themeScrollBar.OpenTheme(0, L"SCROLLBAR");
  658. }
  659. void CXTPScrollBarPaintManager::DrawArrowGlyph(CDC* pDC, CRect rcArrow, BOOL bHorz, BOOL bUpArrow, BOOL bEnabled)
  660. {
  661. int nHeight = min(rcArrow.Width(), rcArrow.Height());
  662. if (nHeight < 6) return;
  663. int x = rcArrow.left + ((rcArrow.Width() - nHeight) / 2) + 2;
  664. int y = rcArrow.top + ((rcArrow.Height() - nHeight) / 2) + 2;
  665. nHeight -= 4;
  666. COLORREF clr = bEnabled ? RGB(0, 0, 0) : GetSysColor(COLOR_3DSHADOW);
  667. HFONT hFont = CreateFont(nHeight, 0, 0, 0, FW_NORMAL, 0, 0, 0, SYMBOL_CHARSET, 0, 0, 0, 0, _T("MARLETT"));
  668. HFONT hOldFont = (HFONT)SelectObject(pDC->GetSafeHdc(), hFont);
  669. SetTextColor(pDC->GetSafeHdc(), clr);
  670. pDC->SetBkMode(TRANSPARENT);
  671. TextOut(pDC->GetSafeHdc(), x, y, bHorz ? (bUpArrow ? _T("3") : _T("4")) : (bUpArrow ? _T("5") : _T("6")), 1);
  672. SelectObject(pDC->GetSafeHdc(), hOldFont);
  673. DeleteObject(hFont);
  674. }
  675. void CXTPScrollBarPaintManager::DrawScrollBar(CDC* pDC, CXTPScrollBase* pGallery)
  676. {
  677. #define GETPARTSTATE(ht, pressed, hot, normal, disabled) 
  678. (!bEnabled ? disabled : nPressetHt == ht ? pressed : nHotHt == ht ? hot : normal)
  679. CXTPScrollBase::SCROLLBARTRACKINFO* pSBTrack = pGallery->GetScrollBarTrackInfo();
  680. CXTPScrollBase::SCROLLBARPOSINFO* pSBInfo = pGallery->GetScrollBarPosInfo();
  681. BOOL nPressetHt = pSBTrack ? (pSBTrack->bTrackThumb || pSBTrack->fHitOld ? pSBInfo->ht : -1) : -1;
  682. BOOL nHotHt = pSBTrack ? -1 : pSBInfo->ht;
  683. int cWidth = (pSBInfo->pxRight - pSBInfo->pxLeft);
  684. if (cWidth <= 0)
  685. {
  686. return;
  687. }
  688. BOOL bEnabled = (pSBInfo->posMax - pSBInfo->posMin - pSBInfo->page + 1 > 0) && pGallery->IsScrollBarEnabled();
  689. int nBtnTrackSize =   pSBInfo->pxThumbBottom - pSBInfo->pxThumbTop;
  690. int nBtnTrackPos = pSBInfo->pxThumbTop - pSBInfo->pxUpArrow;
  691. if (!bEnabled || pSBInfo->pxThumbBottom > pSBInfo->pxDownArrow)
  692. nBtnTrackPos = nBtnTrackSize = 0;
  693. XTPScrollBarStyle style = pGallery->GetScrollBarStyle();
  694. if (pSBInfo->fVert)
  695. {
  696. CRect rcVScroll(pSBInfo->rc);
  697. CRect rcArrowUp(rcVScroll.left, rcVScroll.top, rcVScroll.right, pSBInfo->pxUpArrow);
  698. CRect rcArrowDown(rcVScroll.left, pSBInfo->pxDownArrow, rcVScroll.right, rcVScroll.bottom);
  699. CRect rcTrack(rcVScroll.left, rcArrowUp.bottom, rcVScroll.right, rcArrowDown.top);
  700. CRect rcLowerTrack(rcTrack.left, rcTrack.top, rcTrack.right, rcTrack.top + nBtnTrackPos);
  701. CRect rcBtnTrack(rcTrack.left, rcLowerTrack.bottom, rcTrack.right, rcLowerTrack.bottom + nBtnTrackSize);
  702. CRect rcUpperTrack(rcTrack.left, rcBtnTrack.bottom, rcTrack.right, rcTrack.bottom);
  703. if (style == xtpScrollStyleSystem  && m_themeScrollBar.IsAppThemed())
  704. {
  705. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_ARROWBTN, GETPARTSTATE(XTP_HTSCROLLUP, ABS_UPPRESSED, ABS_UPHOT, ABS_UPNORMAL, ABS_UPDISABLED),  rcArrowUp, NULL);
  706. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_ARROWBTN, GETPARTSTATE(XTP_HTSCROLLDOWN, ABS_DOWNPRESSED, ABS_DOWNHOT, ABS_DOWNNORMAL, ABS_DOWNDISABLED),  rcArrowDown, NULL);
  707. if (!rcTrack.IsRectEmpty())
  708. {
  709. if (!rcLowerTrack.IsRectEmpty())
  710. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_LOWERTRACKVERT, GETPARTSTATE(XTP_HTSCROLLUPPAGE, SCRBS_PRESSED, SCRBS_HOT, SCRBS_NORMAL, SCRBS_DISABLED),  rcLowerTrack, NULL);
  711. if (!rcBtnTrack.IsRectEmpty())
  712. {
  713. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_THUMBBTNVERT, GETPARTSTATE(XTP_HTSCROLLTHUMB, SCRBS_PRESSED, SCRBS_HOT, SCRBS_NORMAL, SCRBS_DISABLED),  rcBtnTrack, NULL);
  714. if (rcBtnTrack.Height() > 13)
  715. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_GRIPPERVERT, GETPARTSTATE(XTP_HTSCROLLTHUMB, SCRBS_PRESSED, SCRBS_HOT, SCRBS_NORMAL, SCRBS_DISABLED),  rcBtnTrack, NULL);
  716. }
  717. if (!rcUpperTrack.IsRectEmpty())
  718. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_UPPERTRACKVERT, GETPARTSTATE(XTP_HTSCROLLDOWNPAGE, SCRBS_PRESSED, SCRBS_HOT, SCRBS_NORMAL, SCRBS_DISABLED),  rcUpperTrack, NULL);
  719. }
  720. }
  721. else
  722. {
  723. if (style == xtpScrollStyleFlat)
  724. {
  725. pDC->FillSolidRect(rcArrowUp, GetXtremeColor(COLOR_3DFACE));
  726. if (bEnabled && nPressetHt == XTP_HTSCROLLUP)
  727. pDC->Draw3dRect(rcArrowUp,GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DHIGHLIGHT));
  728. else
  729. pDC->Draw3dRect(rcArrowUp, GetXtremeColor(COLOR_3DHIGHLIGHT), GetXtremeColor(COLOR_3DSHADOW));
  730. DrawArrowGlyph(pDC, rcArrowUp, FALSE, TRUE, bEnabled);
  731. pDC->FillSolidRect(rcArrowDown, GetXtremeColor(COLOR_3DFACE));
  732. if (bEnabled && nPressetHt == XTP_HTSCROLLDOWN)
  733. pDC->Draw3dRect(rcArrowDown,GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DHIGHLIGHT));
  734. else
  735. pDC->Draw3dRect(rcArrowDown, GetXtremeColor(COLOR_3DHIGHLIGHT), GetXtremeColor(COLOR_3DSHADOW));
  736. DrawArrowGlyph(pDC, rcArrowDown, FALSE, FALSE, bEnabled);
  737. }
  738. else
  739. {
  740. DrawFrameControl(pDC->GetSafeHdc(), &rcArrowUp, DFC_SCROLL, DFCS_SCROLLUP | (!bEnabled ? DFCS_INACTIVE : 0) | (nPressetHt == XTP_HTSCROLLUP ? DFCS_PUSHED : 0));
  741. DrawFrameControl(pDC->GetSafeHdc(), &rcArrowDown, DFC_SCROLL, DFCS_SCROLLDOWN | (!bEnabled ? DFCS_INACTIVE : 0)  | (nPressetHt == XTP_HTSCROLLDOWN ? DFCS_PUSHED : 0));
  742. }
  743. CWnd* pParent = pGallery->GetParentWindow();
  744. HBRUSH hbrRet = (HBRUSH)DefWindowProc(pParent->GetSafeHwnd(), WM_CTLCOLORSCROLLBAR, (WPARAM)pDC->GetSafeHdc(), (LPARAM)pParent->GetSafeHwnd());
  745. ::FillRect(pDC->GetSafeHdc(), &rcTrack, hbrRet);
  746. if (nPressetHt == XTP_HTSCROLLUPPAGE)
  747. {
  748. ::InvertRect(pDC->GetSafeHdc(), &rcLowerTrack);
  749. }
  750. if (!rcTrack.IsRectEmpty() && !rcBtnTrack.IsRectEmpty())
  751. {
  752. pDC->FillSolidRect(rcBtnTrack, GetXtremeColor(COLOR_3DFACE));
  753. if (style == xtpScrollStyleFlat)
  754. {
  755. pDC->Draw3dRect(rcBtnTrack, GetXtremeColor(COLOR_3DHIGHLIGHT), GetXtremeColor(COLOR_3DSHADOW));
  756. }
  757. else
  758. {
  759. DrawEdge(pDC->GetSafeHdc(), &rcBtnTrack, EDGE_RAISED, (UINT)(BF_ADJUST | BF_RECT));
  760. }
  761. }
  762. if (nPressetHt == XTP_HTSCROLLDOWNPAGE)
  763. {
  764. ::InvertRect(pDC->GetSafeHdc(), &rcUpperTrack);
  765. }
  766. }
  767. }
  768. else
  769. {
  770. CRect rcHScroll(pSBInfo->rc);
  771. CRect rcArrowLeft(rcHScroll.left, rcHScroll.top, pSBInfo->pxUpArrow, rcHScroll.bottom);
  772. CRect rcArrowRight(pSBInfo->pxDownArrow, rcHScroll.top, rcHScroll.right, rcHScroll.bottom);
  773. CRect rcTrack(rcArrowLeft.right, rcHScroll.top, rcArrowRight.left, rcHScroll.bottom);
  774. CRect rcLowerTrack(rcTrack.left, rcTrack.top, rcTrack.left + nBtnTrackPos, rcTrack.bottom);
  775. CRect rcBtnTrack(rcLowerTrack.right, rcTrack.top, rcLowerTrack.right + nBtnTrackSize, rcTrack.bottom);
  776. CRect rcUpperTrack(rcBtnTrack.right, rcTrack.top, rcTrack.right, rcTrack.bottom);
  777. if (style == xtpScrollStyleSystem  && m_themeScrollBar.IsAppThemed())
  778. {
  779. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_ARROWBTN, GETPARTSTATE(XTP_HTSCROLLUP, ABS_LEFTPRESSED, ABS_LEFTHOT, ABS_LEFTNORMAL, ABS_LEFTDISABLED),  rcArrowLeft, NULL);
  780. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_ARROWBTN, GETPARTSTATE(XTP_HTSCROLLDOWN, ABS_RIGHTPRESSED, ABS_RIGHTHOT, ABS_RIGHTNORMAL, ABS_RIGHTDISABLED),  rcArrowRight, NULL);
  781. if (!rcTrack.IsRectEmpty())
  782. {
  783. if (!rcLowerTrack.IsRectEmpty())
  784. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_LOWERTRACKHORZ, GETPARTSTATE(XTP_HTSCROLLUPPAGE, SCRBS_PRESSED, SCRBS_HOT, SCRBS_NORMAL, SCRBS_DISABLED),  rcLowerTrack, NULL);
  785. if (!rcBtnTrack.IsRectEmpty())
  786. {
  787. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_THUMBBTNHORZ, GETPARTSTATE(XTP_HTSCROLLTHUMB, SCRBS_PRESSED, SCRBS_HOT, SCRBS_NORMAL, SCRBS_DISABLED),  rcBtnTrack, NULL);
  788. if (rcBtnTrack.Width() > 13)
  789. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_GRIPPERHORZ, GETPARTSTATE(XTP_HTSCROLLTHUMB, SCRBS_PRESSED, SCRBS_HOT, SCRBS_NORMAL, SCRBS_DISABLED),  rcBtnTrack, NULL);
  790. }
  791. if (!rcUpperTrack.IsRectEmpty())
  792. m_themeScrollBar.DrawThemeBackground(pDC->GetSafeHdc(), SBP_UPPERTRACKHORZ, GETPARTSTATE(XTP_HTSCROLLDOWNPAGE, SCRBS_PRESSED, SCRBS_HOT, SCRBS_NORMAL, SCRBS_DISABLED),  rcUpperTrack, NULL);
  793. }
  794. }
  795. else
  796. {
  797. if (style == xtpScrollStyleFlat)
  798. {
  799. pDC->FillSolidRect(rcArrowLeft, GetXtremeColor(COLOR_3DFACE));
  800. if (bEnabled && nPressetHt == XTP_HTSCROLLUP)
  801. pDC->Draw3dRect(rcArrowLeft,GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DHIGHLIGHT));
  802. else
  803. pDC->Draw3dRect(rcArrowLeft, GetXtremeColor(COLOR_3DHIGHLIGHT), GetXtremeColor(COLOR_3DSHADOW));
  804. DrawArrowGlyph(pDC, rcArrowLeft, TRUE, TRUE, bEnabled);
  805. pDC->FillSolidRect(rcArrowRight, GetXtremeColor(COLOR_3DFACE));
  806. if (bEnabled && nPressetHt == XTP_HTSCROLLDOWN)
  807. pDC->Draw3dRect(rcArrowRight,GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DHIGHLIGHT));
  808. else
  809. pDC->Draw3dRect(rcArrowRight, GetXtremeColor(COLOR_3DHIGHLIGHT), GetXtremeColor(COLOR_3DSHADOW));
  810. DrawArrowGlyph(pDC, rcArrowRight, TRUE, FALSE, bEnabled);
  811. }
  812. else
  813. {
  814. DrawFrameControl(pDC->GetSafeHdc(), &rcArrowLeft, DFC_SCROLL, DFCS_SCROLLLEFT | (!bEnabled ? DFCS_INACTIVE : 0) | (nPressetHt == XTP_HTSCROLLUP ? DFCS_PUSHED : 0));
  815. DrawFrameControl(pDC->GetSafeHdc(), &rcArrowRight, DFC_SCROLL, DFCS_SCROLLRIGHT | (!bEnabled ? DFCS_INACTIVE : 0)  | (nPressetHt == XTP_HTSCROLLDOWN ? DFCS_PUSHED : 0));
  816. }
  817. CWnd* pParent = pGallery->GetParentWindow();
  818. HBRUSH hbrRet = (HBRUSH)DefWindowProc(pParent->GetSafeHwnd(), WM_CTLCOLORSCROLLBAR, (WPARAM)pDC->GetSafeHdc(), (LPARAM)pParent->GetSafeHwnd());
  819. ::FillRect(pDC->GetSafeHdc(), &rcTrack, hbrRet);
  820. if (nPressetHt == XTP_HTSCROLLUPPAGE)
  821. {
  822. ::InvertRect(pDC->GetSafeHdc(), &rcLowerTrack);
  823. }
  824. if (!rcTrack.IsRectEmpty() && !rcBtnTrack.IsRectEmpty())
  825. {
  826. pDC->FillSolidRect(rcBtnTrack, GetXtremeColor(COLOR_3DFACE));
  827. if (style == xtpScrollStyleFlat)
  828. {
  829. pDC->Draw3dRect(rcBtnTrack, GetXtremeColor(COLOR_3DHIGHLIGHT), GetXtremeColor(COLOR_3DSHADOW));
  830. }
  831. else
  832. {
  833. DrawEdge(pDC->GetSafeHdc(), &rcBtnTrack, EDGE_RAISED, (UINT)(BF_ADJUST | BF_RECT));
  834. }
  835. }
  836. if (nPressetHt == XTP_HTSCROLLDOWNPAGE)
  837. {
  838. ::InvertRect(pDC->GetSafeHdc(), &rcUpperTrack);
  839. }
  840. }
  841. }
  842. }
  843. //////////////////////////////////////////////////////////////////////////
  844. // CXTPSliderPaintManager
  845. CXTPSliderPaintManager::CXTPSliderPaintManager(CXTPPaintManager* pPaintManager)
  846. : CXTPScrollBarPaintManager(pPaintManager)
  847. {
  848. }
  849. void CXTPSliderPaintManager::RefreshMetrics()
  850. {
  851. CXTPScrollBarPaintManager::RefreshMetrics();
  852. m_cyHScroll = 16;
  853. m_cxHScroll = 16;
  854. m_cThumb = 11;
  855. }
  856. void CXTPSliderPaintManager::DrawScrollBar(CDC* pDC, CXTPScrollBase* pGallery)
  857. {
  858. CXTPScrollBase::SCROLLBARTRACKINFO* pSBTrack = pGallery->GetScrollBarTrackInfo();
  859. CXTPScrollBase::SCROLLBARPOSINFO* pSBInfo = pGallery->GetScrollBarPosInfo();
  860. BOOL nPressetHt = pSBTrack ? (pSBTrack->bTrackThumb || pSBTrack->fHitOld ? pSBInfo->ht : -1) : -1;
  861. BOOL nHotHt = pSBTrack ? -1 : pSBInfo->ht;
  862. int cWidth = (pSBInfo->pxRight - pSBInfo->pxLeft);
  863. if (cWidth <= 0)
  864. return;
  865. BOOL bEnabled = (pSBInfo->posMax - pSBInfo->posMin - pSBInfo->page + 1 > 0) && pGallery->IsScrollBarEnabled();
  866. int nBtnTrackSize =   pSBInfo->pxThumbBottom - pSBInfo->pxThumbTop;
  867. int nBtnTrackPos = pSBInfo->pxThumbTop - pSBInfo->pxUpArrow;
  868. if (!bEnabled || pSBInfo->pxThumbBottom > pSBInfo->pxDownArrow)
  869. nBtnTrackPos = nBtnTrackSize = 0;
  870. COLORREF clrFace = GetXtremeColor(COLOR_3DFACE);
  871. COLORREF clrShadow = GetXtremeColor(COLOR_3DSHADOW);
  872. COLORREF clrLight = GetXtremeColor(COLOR_3DHIGHLIGHT);
  873. if (!pSBInfo->fVert)
  874. {
  875. CRect rcHScroll(pSBInfo->rc);
  876. CRect rcArrowLeft(rcHScroll.left, rcHScroll.top, pSBInfo->pxUpArrow, rcHScroll.bottom);
  877. CRect rcArrowRight(pSBInfo->pxDownArrow, rcHScroll.top, rcHScroll.right, rcHScroll.bottom);
  878. CRect rcTrack(rcArrowLeft.right, rcHScroll.top, rcArrowRight.left, rcHScroll.bottom);
  879. CRect rcBtnTrack(rcTrack.left + nBtnTrackPos, rcTrack.top, rcTrack.left + nBtnTrackPos + nBtnTrackSize, rcTrack.bottom);
  880. CRect rcTrackDest(CPoint(rcTrack.left, (rcTrack.top + rcTrack.bottom - 2) / 2), CSize(rcTrack.Width(), 2));
  881. pDC->FillSolidRect(rcTrackDest.left, rcTrackDest.top, rcTrackDest.Width(), 1, clrShadow);
  882. pDC->FillSolidRect(rcTrackDest.left, rcTrackDest.top + 1, rcTrackDest.Width(), 1, clrLight);
  883. CXTPScrollBase::SLIDERTICKS* pTicks = pGallery->GetTicks();
  884. if (!pTicks || (pSBInfo->posMax <= pSBInfo->posMin))
  885. {
  886. CRect rcTrackTickDest(CPoint((rcTrackDest.left + rcTrackDest.right - 2) / 2,
  887. (rcTrackDest.top + rcTrackDest.bottom - 8) / 2), CSize(2, 8));
  888. pDC->FillSolidRect(rcTrackTickDest.left, rcTrackTickDest.top, 1, 4, clrShadow);
  889. pDC->FillSolidRect(rcTrackTickDest.left, rcTrackTickDest.top + 5, 1, 2, clrShadow);
  890. pDC->FillSolidRect(rcTrackTickDest.left + 1, rcTrackTickDest.top + 1, 1, 7, clrLight);
  891. }
  892. else
  893. {
  894. rcTrackDest.DeflateRect(6, 0);
  895. for (int i = 0; i < pTicks->nCount; i++)
  896. {
  897. double dTick = pTicks->pTicks[i];
  898. double dPos = (dTick - pSBInfo->posMin) * rcTrackDest.Width() / (pSBInfo->posMax - pSBInfo->posMin);
  899. if (dPos >= 0 && dPos <= rcTrackDest.Width())
  900. {
  901. CRect rcTrackTickDest(CPoint(rcTrackDest.left + (int)dPos - 1,
  902. (rcTrackDest.top + rcTrackDest.bottom - 8) / 2), CSize(2, 8));
  903. pDC->FillSolidRect(rcTrackTickDest.left, rcTrackTickDest.top, 1, 4, clrShadow);
  904. pDC->FillSolidRect(rcTrackTickDest.left, rcTrackTickDest.top + 5, 1, 2, clrShadow);
  905. pDC->FillSolidRect(rcTrackTickDest.left + 1, rcTrackTickDest.top + 1, 1, 7, clrLight);
  906. }
  907. }
  908. }
  909. m_pPaintManager->AlphaEllipse(pDC, rcArrowLeft, clrShadow, nHotHt == XTP_HTSCROLLUP ? clrLight : clrFace);
  910. if (nPressetHt != XTP_HTSCROLLUP)
  911. {
  912. rcArrowLeft.DeflateRect(1, 1);
  913. m_pPaintManager->AlphaEllipse(pDC, rcArrowLeft, clrLight, nHotHt == XTP_HTSCROLLUP ? clrLight : clrFace);
  914. }
  915. CPoint ptCenter = rcArrowLeft.CenterPoint();
  916. pDC->FillSolidRect(ptCenter.x - 4, ptCenter.y - 1, 8, 2, 0);
  917. m_pPaintManager->AlphaEllipse(pDC, rcArrowRight, clrShadow, nHotHt == XTP_HTSCROLLDOWN ? clrLight : clrFace);
  918. if (nPressetHt != XTP_HTSCROLLDOWN)
  919. {
  920. rcArrowRight.DeflateRect(1, 1);
  921. m_pPaintManager->AlphaEllipse(pDC, rcArrowRight, clrLight, nHotHt == XTP_HTSCROLLDOWN ? clrLight : clrFace);
  922. }
  923. ptCenter = rcArrowRight.CenterPoint();
  924. pDC->FillSolidRect(ptCenter.x - 4, ptCenter.y - 1, 8, 2, 0);
  925. pDC->FillSolidRect(ptCenter.x - 1, ptCenter.y - 4, 2, 8, 0);
  926. if (bEnabled)
  927. {
  928. CRect rc(CPoint((rcBtnTrack.left + rcBtnTrack.right - 8) / 2,
  929. (rcBtnTrack.top + rcBtnTrack.bottom - 13) / 2), CSize(8, 13));
  930. POINT pts[] = {rc.left, rc.top, rc.right, rc.top,
  931. rc.right,  rc.bottom - 4, rc.left + 4, rc.bottom, rc.left, rc.bottom - 4, rc.left, rc.top};
  932. CXTPPenDC pen (*pDC, nHotHt == XTP_HTSCROLLTHUMB ? clrLight : clrFace);
  933. CXTPBrushDC brush (*pDC, nHotHt == XTP_HTSCROLLTHUMB ? clrLight : clrFace);
  934. pDC->Polygon(pts, sizeof(pts) / sizeof(POINT));
  935. pen.Color(clrShadow);
  936. pDC->Polyline(pts, sizeof(pts) / sizeof(POINT));
  937. if (nPressetHt != XTP_HTSCROLLTHUMB)
  938. {
  939. POINT pts2[] = {rc.left + 1, rc.top + 1, rc.right - 1, rc.top + 1,
  940. rc.right - 1,  rc.bottom - 4, rc.left + 4, rc.bottom - 1, rc.left + 1, rc.bottom - 4, rc.left + 1, rc.top + 1};
  941. pen.Color(clrLight);
  942. pDC->Polyline(pts2, sizeof(pts2) / sizeof(POINT));
  943. }
  944. }
  945. }
  946. }