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

对话框与窗口

开发平台:

Visual C++

  1. // XTPSkinObjectScrollBar.cpp: implementation of the CXTPSkinObjectScrollBar class.
  2. //
  3. // This file is a part of the XTREME SKINFRAMEWORK 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 "XTPSkinManager.h"
  23. #include "XTPSkinObjectScrollBar.h"
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char THIS_FILE[]=__FILE__;
  27. #define new DEBUG_NEW
  28. #endif
  29. #define IDSYS_SCROLL 0xFA45
  30. CRect CXTPSkinObjectFrame::GetScrollBarRect(int nBar)
  31. {
  32. CRect rcClient;
  33. GetClientRect(&rcClient);
  34. if (nBar == SB_CTL)
  35. {
  36. return rcClient;
  37. }
  38. CRect rc;
  39. GetWindowRect(rc);
  40. ScreenToClient(rc);
  41. if (nBar == SB_VERT)
  42. {
  43. rc.bottom = rcClient.bottom - rc.top;
  44. rc.top = rcClient.top - rc.top;
  45. if (GetExStyle() & WS_EX_LEFTSCROLLBAR)
  46. {
  47. rc.left = rcClient.left - rc.left - GetMetrics()->m_cxVScroll;
  48. }
  49. else
  50. {
  51. rc.left = rcClient.right - rc.left;
  52. }
  53. rc.right = rc.left + GetMetrics()->m_cxVScroll;
  54. }
  55. if (nBar == SB_HORZ)
  56. {
  57. rc.right = rcClient.right - rc.left;
  58. rc.left = rcClient.left - rc.left;
  59. rc.top = rcClient.bottom - rc.top;
  60. rc.bottom = rc.top + GetMetrics()->m_cyHScroll;
  61. }
  62. return rc;
  63. }
  64. void CXTPSkinObjectFrame::SetupScrollInfo(XTP_SKINSCROLLBARPOSINFO* pSBInfo)
  65. {
  66. CRect rc = GetScrollBarRect(pSBInfo->nBar);
  67. SCROLLINFO si;
  68. si.cbSize = sizeof(SCROLLINFO);
  69. si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
  70. ::GetScrollInfo(m_hWnd, pSBInfo->nBar, &si);
  71. CalcScrollBarInfo(&rc, pSBInfo, &si);
  72. }
  73. void CXTPSkinObjectFrame::RedrawScrollBar(int nBar)
  74. {
  75. ASSERT(nBar == SB_VERT || nBar == SB_HORZ);
  76. RedrawScrollBar(&m_spi[nBar]);
  77. }
  78. void CXTPSkinObjectFrame::RedrawScrollBar(XTP_SKINSCROLLBARPOSINFO* pSBInfo)
  79. {
  80. if (!pSBInfo->fVisible )
  81. return;
  82. if (!IsWindow(m_hWnd))
  83. return;
  84. CDC* pDC = pSBInfo->nBar == SB_CTL ? (CDC*)new CClientDC(this) : (CDC*)new CWindowDC(this);
  85. if (pDC)
  86. {
  87. CRect rc = GetScrollBarRect(pSBInfo->nBar);
  88. CXTPBufferDCEx dcMem(*pDC, rc);
  89. if (!m_pSBTrack || !m_pSBTrack->bTrackThumb)
  90. SetupScrollInfo(pSBInfo);
  91. DrawScrollBar(&dcMem, pSBInfo);
  92. }
  93. delete pDC;
  94. }
  95. int CXTPSkinObjectFrame::HitTestScrollBar(XTP_SKINSCROLLBARPOSINFO* pSBInfo, POINT pt)
  96. {
  97. if (!pSBInfo->fVisible)
  98. return HTNOWHERE;
  99. int px = pSBInfo->fVert ? pt.y : pt.x;
  100. if (!::PtInRect(&pSBInfo->rc, pt))
  101. return HTNOWHERE;
  102. if (px < pSBInfo->pxUpArrow)
  103. return XTP_HTSCROLLUP;
  104. if (px >= pSBInfo->pxDownArrow)
  105. return XTP_HTSCROLLDOWN;
  106. if (px < pSBInfo->pxThumbTop)
  107. return XTP_HTSCROLLUPPAGE;
  108. if (px < pSBInfo->pxThumbBottom)
  109. return XTP_HTSCROLLTHUMB;
  110. if (px < pSBInfo->pxDownArrow)
  111. return XTP_HTSCROLLDOWNPAGE;
  112. return HTERROR;
  113. }
  114. void CXTPSkinObjectFrame::CalcScrollBarInfo(LPRECT lprc, XTP_SKINSCROLLBARPOSINFO* pSBInfo, SCROLLINFO* pSI)
  115. {
  116. int cpx;
  117. DWORD dwRange;
  118. int denom;
  119. BOOL fVert = pSBInfo->fVert;
  120. pSBInfo->rc = *lprc;
  121. if (fVert)
  122. {
  123. pSBInfo->pxTop = lprc->top;
  124. pSBInfo->pxBottom = lprc->bottom;
  125. pSBInfo->pxLeft = lprc->left;
  126. pSBInfo->pxRight = lprc->right;
  127. pSBInfo->cpxThumb = GetMetrics()->m_cyVScroll;
  128. }
  129. else
  130. {
  131. pSBInfo->pxTop = lprc->left;
  132. pSBInfo->pxBottom = lprc->right;
  133. pSBInfo->pxLeft = lprc->top;
  134. pSBInfo->pxRight = lprc->bottom;
  135. pSBInfo->cpxThumb = GetMetrics()->m_cxHScroll;
  136. }
  137. pSBInfo->pos = pSI->nPos;
  138. pSBInfo->page = pSI->nPage;
  139. pSBInfo->posMin = pSI->nMin;
  140. pSBInfo->posMax = pSI->nMax;
  141. dwRange = ((DWORD)(pSBInfo->posMax - pSBInfo->posMin)) + 1;
  142. cpx = min((pSBInfo->pxBottom - pSBInfo->pxTop) / 2, pSBInfo->cpxThumb);
  143. pSBInfo->pxUpArrow  = pSBInfo->pxTop    + cpx;
  144. pSBInfo->pxDownArrow = pSBInfo->pxBottom - cpx;
  145. if ((pSBInfo->page != 0) && (dwRange != 0))
  146. {
  147. int i = MulDiv(pSBInfo->pxDownArrow - pSBInfo->pxUpArrow,
  148. pSBInfo->page, dwRange);
  149. pSBInfo->cpxThumb = max(pSBInfo->cpxThumb / 2, i);
  150. }
  151. pSBInfo->pxMin = pSBInfo->pxTop + cpx;
  152. pSBInfo->cpx = pSBInfo->pxBottom - cpx - pSBInfo->cpxThumb - pSBInfo->pxMin;
  153. denom = dwRange - (pSBInfo->page ? pSBInfo->page : 1);
  154. if (denom)
  155. pSBInfo->pxThumbTop = MulDiv(pSBInfo->pos - pSBInfo->posMin,
  156. pSBInfo->cpx, denom) + pSBInfo->pxMin;
  157. else
  158. pSBInfo->pxThumbTop = pSBInfo->pxMin - 1;
  159. pSBInfo->pxThumbBottom = pSBInfo->pxThumbTop + pSBInfo->cpxThumb;
  160. }
  161. void XTPSkinCalcTrackDragRect(XTP_SKINSCROLLBARTRACKINFO* pSBTrack)
  162. {
  163. int     cx;
  164. int     cy;
  165. LPINT   pwX, pwY;
  166. pwX = pwY = (LPINT)&pSBTrack->rcTrack;
  167. if (pSBTrack->fTrackVert)
  168. {
  169. cy = GetSystemMetrics(SM_CYVTHUMB);
  170. pwY++;
  171. }
  172. else
  173. {
  174. cy = GetSystemMetrics(SM_CXHTHUMB);
  175. pwX++;
  176. }
  177. cx = (pSBTrack->pSBInfo->pxRight - pSBTrack->pSBInfo->pxLeft) * 8;
  178. cy *= 2;
  179. *(pwX + 0) = pSBTrack->pSBInfo->pxLeft - cx;
  180. *(pwY + 0) = pSBTrack->pSBInfo->pxTop - cy;
  181. *(pwX + 2) = pSBTrack->pSBInfo->pxRight + cx;
  182. *(pwY + 2) = pSBTrack->pSBInfo->pxBottom + cy;
  183. }
  184. void CXTPSkinObjectFrame::DoScroll(HWND hwnd, HWND hWndSBNotify, int cmd, int pos, BOOL fVert)
  185. {
  186. if (!hWndSBNotify)
  187. return;
  188. ::SendMessage(hWndSBNotify, (UINT)(fVert ? WM_VSCROLL : WM_HSCROLL),
  189. MAKELONG(cmd, pos), (LPARAM)hwnd);
  190. }
  191. void CXTPSkinObjectFrame::EndScroll(BOOL fCancel)
  192. {
  193. XTP_SKINSCROLLBARTRACKINFO* pSBTrack = m_pSBTrack;
  194. if (pSBTrack)
  195. {
  196. pSBTrack->cmdSB = 0;
  197. ReleaseCapture();
  198. if (pSBTrack->bTrackThumb)
  199. {
  200. if (fCancel)
  201. {
  202. pSBTrack->posOld = pSBTrack->pSBInfo->pos;
  203. }
  204. DoScroll(pSBTrack->hWndSB, pSBTrack->hWndSBNotify,
  205. SB_THUMBPOSITION, pSBTrack->posOld, pSBTrack->fTrackVert);
  206. RedrawScrollBar(pSBTrack->pSBInfo);
  207. }
  208. else
  209. {
  210. if (pSBTrack->hTimerSB != 0)
  211. {
  212. KillTimer(pSBTrack->hTimerSB);
  213. pSBTrack->hTimerSB = 0;
  214. }
  215. }
  216. DoScroll(pSBTrack->hWndSB, pSBTrack->hWndSBNotify,
  217. SB_ENDSCROLL, 0, pSBTrack->fTrackVert);
  218. }
  219. }
  220. int SBPosFromPx(XTP_SKINSCROLLBARPOSINFO*  pSBInfo, int px)
  221. {
  222. if (px < pSBInfo->pxMin)
  223. {
  224. return pSBInfo->posMin;
  225. }
  226. if (px >= pSBInfo->pxMin + pSBInfo->cpx)
  227. {
  228. return (pSBInfo->posMax - (pSBInfo->page ? pSBInfo->page - 1 : 0));
  229. }
  230. if (pSBInfo->cpx)
  231. return (pSBInfo->posMin + MulDiv(pSBInfo->posMax - pSBInfo->posMin -
  232. (pSBInfo->page ? pSBInfo->page - 1 : 0),
  233. px - pSBInfo->pxMin, pSBInfo->cpx));
  234. else
  235. return (pSBInfo->posMin - 1);
  236. }
  237. void CXTPSkinObjectFrame::MoveThumb(int px)
  238. {
  239. XTP_SKINSCROLLBARTRACKINFO* pSBTrack = m_pSBTrack;
  240. if ((pSBTrack == NULL) || (px == pSBTrack->pxOld))
  241. return;
  242. XTP_SKINSCROLLBARPOSINFO* pSBInfo = m_pSBTrack->pSBInfo;
  243. pxReCalc:
  244. pSBTrack->posNew = SBPosFromPx(pSBInfo, px);
  245. if (pSBTrack->posNew != pSBTrack->posOld)
  246. {
  247. DoScroll(pSBTrack->hWndSB, pSBTrack->hWndSBNotify, SB_THUMBTRACK, pSBTrack->posNew, pSBTrack->fTrackVert);
  248. pSBTrack->posOld = pSBTrack->posNew;
  249. if (px >= pSBInfo->pxMin + pSBInfo->cpx)
  250. {
  251. px = pSBInfo->pxMin + pSBInfo->cpx;
  252. goto pxReCalc;
  253. }
  254. }
  255. pSBInfo->pxThumbTop = px;
  256. pSBInfo->pxThumbBottom = pSBInfo->pxThumbTop + pSBInfo->cpxThumb;
  257. pSBTrack->pxOld = px;
  258. RedrawScrollBar(pSBTrack->pSBInfo);
  259. }
  260. void CXTPSkinObjectFrame::TrackThumb(UINT message, CPoint pt)
  261. {
  262. XTP_SKINSCROLLBARTRACKINFO* pSBTrack = m_pSBTrack;
  263. if (!pSBTrack)
  264. return;
  265. XTP_SKINSCROLLBARPOSINFO* pSBInfo = pSBTrack->pSBInfo;
  266. if (HIBYTE(message) != HIBYTE(WM_MOUSEFIRST))
  267. return;
  268. if (pSBInfo == NULL)
  269. return;
  270. int px;
  271. if (!PtInRect(&pSBTrack->rcTrack, pt))
  272. px = pSBInfo->pxStart;
  273. else
  274. {
  275. px = (pSBTrack->fTrackVert ? pt.y : pt.x) + pSBTrack->dpxThumb;
  276. if (px < pSBInfo->pxMin)
  277. px = pSBInfo->pxMin;
  278. else if (px >= pSBInfo->pxMin + pSBInfo->cpx)
  279. px = pSBInfo->pxMin + pSBInfo->cpx;
  280. }
  281. MoveThumb(px);
  282. pSBTrack->fHitOld = TRUE;
  283. if (message == WM_LBUTTONUP || GetKeyState(VK_LBUTTON) >= 0)
  284. {
  285. EndScroll(FALSE);
  286. }
  287. }
  288. void CXTPSkinObjectFrame::TrackBox(UINT message, CPoint point)
  289. {
  290. XTP_SKINSCROLLBARTRACKINFO* pSBTrack = m_pSBTrack;
  291. if (pSBTrack == NULL)
  292. return;
  293. if (message != WM_NULL && HIBYTE(message) != HIBYTE(WM_MOUSEFIRST))
  294. return;
  295. if ((pSBTrack->cmdSB == SB_PAGEUP || pSBTrack->cmdSB == SB_PAGEDOWN))
  296. {
  297. int* pLength = (int *)&pSBTrack->rcTrack;
  298. if (pSBTrack->fTrackVert)
  299. pLength++;
  300. if (pSBTrack->cmdSB == SB_PAGEUP)
  301. pLength[2] = pSBTrack->pSBInfo->pxThumbTop;
  302. else
  303. pLength[0] = pSBTrack->pSBInfo->pxThumbBottom;
  304. }
  305. BOOL fHit = PtInRect(&pSBTrack->rcTrack, point);
  306. BOOL fHitChanged = fHit != (BOOL)pSBTrack->fHitOld;
  307. if (fHitChanged)
  308. {
  309. pSBTrack->fHitOld = fHit;
  310. RedrawScrollBar(pSBTrack->pSBInfo);
  311. }
  312. int cmsTimer = GetDoubleClickTime() / 10;
  313. switch (message)
  314. {
  315. case WM_LBUTTONUP:
  316. EndScroll(FALSE);
  317. break;
  318. case WM_LBUTTONDOWN:
  319. pSBTrack->hTimerSB = 0;
  320. cmsTimer = GetDoubleClickTime() * 4 / 5;
  321. /*
  322. *** FALL THRU **
  323. */
  324. case WM_MOUSEMOVE:
  325. if (fHit && fHitChanged)
  326. {
  327. pSBTrack->hTimerSB = SetTimer(IDSYS_SCROLL, cmsTimer, NULL);
  328. DoScroll(pSBTrack->hWndSB, pSBTrack->hWndSBNotify,
  329. pSBTrack->cmdSB, 0, pSBTrack->fTrackVert);
  330. }
  331. }
  332. }
  333. void CXTPSkinObjectFrame::TrackInit(CPoint point, XTP_SKINSCROLLBARPOSINFO* pSBInfo, BOOL bDirect)
  334. {
  335. int px = (pSBInfo->fVert ? point.y : point.x);
  336. XTP_SKINSCROLLBARTRACKINFO* pSBTrack = new XTP_SKINSCROLLBARTRACKINFO;
  337. memset(pSBTrack, 0, sizeof(XTP_SKINSCROLLBARTRACKINFO));
  338. pSBTrack->fTrackVert = pSBInfo->fVert;
  339. if (pSBInfo->nBar == SB_CTL)
  340. {
  341. pSBTrack->hWndSB = m_hWnd;
  342. pSBTrack->hWndSBNotify = ::GetParent(m_hWnd);
  343. pSBTrack->fNonClient = FALSE;
  344. }
  345. else
  346. {
  347. pSBTrack->hWndSB = NULL;
  348. pSBTrack->hWndSBNotify = m_hWnd;
  349. pSBTrack->fNonClient = TRUE;
  350. }
  351. pSBTrack->cmdSB = (UINT)-1;
  352. pSBTrack->nBar = pSBInfo->nBar;
  353. pSBTrack->bTrackThumb = FALSE;
  354. pSBTrack->pSBInfo = pSBInfo;
  355. m_pSBTrack = pSBTrack;
  356. RECT rcSB;
  357. LPINT pwX = (LPINT)&rcSB;
  358. LPINT pwY = pwX + 1;
  359. if (!pSBInfo->fVert)
  360. pwX = pwY--;
  361. *(pwX + 0) = pSBInfo->pxLeft;
  362. *(pwY + 0) = pSBInfo->pxTop;
  363. *(pwX + 2) = pSBInfo->pxRight;
  364. *(pwY + 2) = pSBInfo->pxBottom;
  365. if (px < pSBInfo->pxUpArrow)
  366. {
  367. pSBInfo->ht = XTP_HTSCROLLUP;
  368. pSBTrack->cmdSB = SB_LINEUP;
  369. *(pwY + 2) = pSBInfo->pxUpArrow;
  370. }
  371. else if (px >= pSBInfo->pxDownArrow)
  372. {
  373. pSBInfo->ht = XTP_HTSCROLLDOWN;
  374. pSBTrack->cmdSB = SB_LINEDOWN;
  375. *(pwY + 0) = pSBInfo->pxDownArrow;
  376. }
  377. else if (px < pSBInfo->pxThumbTop)
  378. {
  379. pSBInfo->ht = XTP_HTSCROLLUPPAGE;
  380. pSBTrack->cmdSB = SB_PAGEUP;
  381. *(pwY + 0) = pSBInfo->pxUpArrow;
  382. *(pwY + 2) = pSBInfo->pxThumbTop;
  383. }
  384. else if (px < pSBInfo->pxThumbBottom)
  385. {
  386. pSBInfo->ht = XTP_HTSCROLLTHUMB;
  387. DoThumbPos:
  388. if (pSBInfo->pxDownArrow - pSBInfo->pxUpArrow <= pSBInfo->cpxThumb)
  389. {
  390. delete m_pSBTrack;
  391. m_pSBTrack = NULL;
  392. return;
  393. }
  394. pSBTrack->cmdSB = SB_THUMBPOSITION;
  395. XTPSkinCalcTrackDragRect(pSBTrack);
  396. pSBTrack->pxOld = pSBInfo->pxStart = pSBInfo->pxThumbTop;
  397. pSBTrack->posNew = pSBTrack->posOld = pSBInfo->pos;
  398. pSBTrack->dpxThumb = pSBInfo->pxStart - px;
  399. pSBTrack->bTrackThumb = TRUE;
  400. SetCapture();
  401. DoScroll(pSBTrack->hWndSB, pSBTrack->hWndSBNotify,
  402. SB_THUMBTRACK, pSBTrack->posOld, pSBTrack->fTrackVert);
  403. }
  404. else if (px < pSBInfo->pxDownArrow)
  405. {
  406. pSBInfo->ht = XTP_HTSCROLLDOWNPAGE;
  407. pSBTrack->cmdSB = SB_PAGEDOWN;
  408. *(pwY + 0) = pSBInfo->pxThumbBottom;
  409. *(pwY + 2) = pSBInfo->pxDownArrow;
  410. }
  411. if ((bDirect && pSBTrack->cmdSB != SB_LINEUP && pSBTrack->cmdSB != SB_LINEDOWN))
  412. {
  413. if (pSBTrack->cmdSB != SB_THUMBPOSITION)
  414. {
  415. goto DoThumbPos;
  416. }
  417. pSBTrack->dpxThumb = -(pSBInfo->cpxThumb / 2);
  418. }
  419. SetCapture();
  420. if (pSBTrack->cmdSB != SB_THUMBPOSITION)
  421. {
  422. CopyRect(&pSBTrack->rcTrack, &rcSB);
  423. }
  424. if (!pSBTrack->bTrackThumb)
  425. {
  426. TrackBox(WM_LBUTTONDOWN, point);
  427. }
  428. else
  429. {
  430. TrackThumb(WM_LBUTTONDOWN, point);
  431. }
  432. while (::GetCapture() == m_hWnd)
  433. {
  434. while (::GetCapture() == m_hWnd)
  435. {
  436. MSG msg;
  437. if (!::GetMessage(&msg, NULL, 0, 0))
  438. {
  439. AfxPostQuitMessage((int)msg.wParam);
  440. break;
  441. }
  442. UINT cmd = msg.message;
  443. if (cmd == WM_TIMER && msg.wParam == IDSYS_SCROLL)
  444. {
  445. ContScroll();
  446. }
  447. else if (cmd >= WM_MOUSEFIRST && cmd <= WM_MOUSELAST)
  448. {
  449. CPoint ptScreen = msg.pt;
  450. if (pSBTrack->fNonClient)
  451. ScreenToFrame(&ptScreen);
  452. else
  453. ScreenToClient(&ptScreen);
  454. if (!pSBTrack->bTrackThumb)
  455. {
  456. TrackBox(cmd, ptScreen);
  457. }
  458. else
  459. {
  460. TrackThumb(cmd, ptScreen);
  461. }
  462. }
  463. else
  464. {
  465. TranslateMessage(&msg);
  466. DispatchMessage(&msg);
  467. }
  468. }
  469. }
  470. if (pSBTrack->hTimerSB != 0)
  471. {
  472. KillTimer(pSBTrack->hTimerSB);
  473. }
  474. pSBInfo->ht = 0;
  475. delete m_pSBTrack;
  476. m_pSBTrack = NULL;
  477. RedrawScrollBar(pSBInfo);
  478. }
  479. void CXTPSkinObjectFrame::ContScroll()
  480. {
  481. XTP_SKINSCROLLBARTRACKINFO* pSBTrack = m_pSBTrack;
  482. ASSERT(pSBTrack);
  483. if (pSBTrack == NULL)
  484. return;
  485. CPoint pt;
  486. GetCursorPos(&pt);
  487. if (pSBTrack->fNonClient)
  488. ScreenToFrame(&pt);
  489. else
  490. ScreenToClient(&pt);
  491. TrackBox(WM_NULL, pt);
  492. if (pSBTrack->fHitOld)
  493. {
  494. pSBTrack->hTimerSB = SetTimer( IDSYS_SCROLL, GetDoubleClickTime() / 10, NULL);
  495. DoScroll(pSBTrack->hWndSB, pSBTrack->hWndSBNotify,
  496. pSBTrack->cmdSB, 0, pSBTrack->fTrackVert);
  497. }
  498. }
  499. void CXTPSkinObjectFrame::DrawScrollBar(CDC* pDC, XTP_SKINSCROLLBARPOSINFO* pSBInfo)
  500. {
  501. GetSkinManager()->GetSchema()->DrawThemeScrollBar(pDC, this, pSBInfo);
  502. }
  503. //////////////////////////////////////////////////////////////////////////
  504. // CXTPSkinObjectScrollBar
  505. IMPLEMENT_DYNCREATE(CXTPSkinObjectScrollBar, CXTPSkinObjectFrame)
  506. CXTPSkinObjectScrollBar::CXTPSkinObjectScrollBar()
  507. {
  508. ZeroMemory(&m_spiCtl, sizeof(XTP_SKINSCROLLBARPOSINFO));
  509. m_strClassName = _T("SCROLLBAR");
  510. }
  511. CXTPSkinObjectScrollBar::~CXTPSkinObjectScrollBar()
  512. {
  513. }
  514. BEGIN_MESSAGE_MAP(CXTPSkinObjectScrollBar, CXTPSkinObjectFrame)
  515. //{{AFX_MSG_MAP(CXTPSkinObjectScrollBar)
  516. ON_WM_CREATE()
  517. ON_WM_PAINT()
  518. ON_MESSAGE(WM_PRINTCLIENT, OnPrintClient)
  519. ON_WM_ENABLE()
  520. ON_WM_MOUSEMOVE()
  521. ON_MESSAGE_VOID(WM_MOUSELEAVE, OnMouseLeave)
  522. ON_WM_LBUTTONDOWN()
  523. ON_WM_LBUTTONDBLCLK()
  524. ON_MESSAGE(SBM_SETSCROLLINFO, OnSetScrollInfo)
  525. ON_MESSAGE(SBM_GETSCROLLINFO, OnGetScrollInfo)
  526. ON_MESSAGE(SBM_SETPOS, OnSetScrollPos)
  527. ON_WM_SETFOCUS()
  528. //}}AFX_MSG_MAP
  529. END_MESSAGE_MAP()
  530. /////////////////////////////////////////////////////////////////////////////
  531. // CXTPSkinObjectScrollBar message handlers
  532. int CXTPSkinObjectScrollBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
  533. {
  534. if (CXTPSkinObjectFrame::OnCreate(lpCreateStruct) == -1)
  535. return -1;
  536. Invalidate(FALSE);
  537. return 0;
  538. }
  539. LRESULT CXTPSkinObjectScrollBar::OnPrintClient(WPARAM wParam, LPARAM /*lParam*/)
  540. {
  541. CDC* pDC = CDC::FromHandle((HDC)wParam);
  542. if (pDC) OnDraw(pDC);
  543. return 1;
  544. }
  545. void CXTPSkinObjectScrollBar::OnPaint()
  546. {
  547. CXTPSkinObjectPaintDC dc(this); // device context for painting
  548. OnDraw(&dc);
  549. }
  550. void CXTPSkinObjectScrollBar::OnDraw(CDC* pDC)
  551. {
  552. CRect rc;
  553. GetClientRect(&rc);
  554. BOOL fSize = ((GetStyle() & (SBS_SIZEBOX | SBS_SIZEGRIP)) != 0);
  555. CXTPBufferDC dcMem(*pDC, rc);
  556. if (!fSize)
  557. {
  558. m_spiCtl.fVert = GetStyle() & SBS_VERT;
  559. m_spiCtl.fVisible = TRUE;
  560. m_spiCtl.nBar = SB_CTL;
  561. if (!m_pSBTrack || !m_pSBTrack->bTrackThumb)
  562. SetupScrollInfo(&m_spiCtl);
  563. DrawScrollBar(&dcMem, &m_spiCtl);
  564. }
  565. else
  566. {
  567. CXTPSkinManagerClass* pClassScrollBar = GetSkinManager()->GetSkinClass(_T("SCROLLBAR"));
  568. FillBackground(&dcMem, rc);
  569. if (GetStyle() & SBS_SIZEGRIP)
  570. {
  571. pClassScrollBar->DrawThemeBackground(&dcMem, SBP_SIZEBOX, SZB_RIGHTALIGN, rc);
  572. }
  573. }
  574. }
  575. void CXTPSkinObjectScrollBar::OnEnable(BOOL bEnable)
  576. {
  577. CXTPSkinObjectFrame::OnEnable(bEnable);
  578. Invalidate(FALSE);
  579. }
  580. void CXTPSkinObjectScrollBar::OnMouseLeave()
  581. {
  582. OnMouseMove(0, CPoint(-1, -1));
  583. }
  584. void CXTPSkinObjectScrollBar::OnMouseMove(UINT /*nFlags*/, CPoint point)
  585. {
  586. BOOL fSize = ((GetStyle() & (SBS_SIZEBOX | SBS_SIZEGRIP)) != 0);
  587. if (fSize)
  588. return;
  589. int ht = HitTestScrollBar(&m_spiCtl, point);
  590. if (ht != m_spiCtl.ht)
  591. {
  592. m_spiCtl.ht = ht;
  593. Invalidate(FALSE);
  594. if (m_spiCtl.ht != HTNOWHERE)
  595. {
  596. TRACKMOUSEEVENT tme = {sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd, HOVER_DEFAULT};
  597. _TrackMouseEvent(&tme);
  598. }
  599. }
  600. }
  601. void CXTPSkinObjectScrollBar::OnLButtonDown(UINT nFlags, CPoint point)
  602. {
  603. BOOL fSize = ((GetStyle() & (SBS_SIZEBOX | SBS_SIZEGRIP)) != 0);
  604. if (fSize)
  605. {
  606. CXTPSkinObjectFrame::OnLButtonDown(nFlags, point);
  607. return;
  608. }
  609. TrackInit(point, &m_spiCtl, (GetKeyState(VK_SHIFT) < 0) ? TRUE : FALSE);
  610. }
  611. void CXTPSkinObjectScrollBar::OnLButtonDblClk(UINT nFlags, CPoint point)
  612. {
  613. BOOL fSize = ((GetStyle() & (SBS_SIZEBOX | SBS_SIZEGRIP)) != 0);
  614. if (fSize)
  615. {
  616. CXTPSkinObjectFrame::OnLButtonDblClk(nFlags, point);
  617. return;
  618. }
  619. OnLButtonDown(nFlags, point);
  620. }
  621. LRESULT CXTPSkinObjectScrollBar::OnSetScrollInfo(WPARAM wParam, LPARAM lParam)
  622. {
  623. LRESULT lResult = DefWindowProc(SBM_SETSCROLLINFO, FALSE, lParam);
  624. if (wParam && IsWindowVisible())
  625. {
  626. CClientDC dc(this);
  627. OnDraw(&dc);
  628. }
  629. return lResult;
  630. }
  631. LRESULT CXTPSkinObjectScrollBar::OnGetScrollInfo(WPARAM wParam, LPARAM lParam)
  632. {
  633. LRESULT bResult = DefWindowProc(SBM_GETSCROLLINFO, wParam, lParam);
  634. LPSCROLLINFO lpsi = (LPSCROLLINFO)lParam;
  635. if (lpsi && (lpsi->fMask & SIF_TRACKPOS) && m_pSBTrack)
  636. {
  637. lpsi->nTrackPos = m_pSBTrack->posNew;
  638. }
  639. return bResult;
  640. }
  641. LRESULT CXTPSkinObjectScrollBar::OnSetScrollPos(WPARAM wParam, LPARAM lParam)
  642. {
  643. LRESULT lResult = DefWindowProc(SBM_SETPOS, wParam, FALSE);
  644. if (lParam && IsWindowVisible())
  645. {
  646. CClientDC dc(this);
  647. OnDraw(&dc);
  648. }
  649. return lResult;
  650. }
  651. void CXTPSkinObjectScrollBar::OnSetFocus(CWnd* pOldWnd)
  652. {
  653. pOldWnd;
  654. }