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

对话框与窗口

开发平台:

Visual C++

  1. // XTPSkinObjectSpin.cpp: implementation of the CXTPSkinObjectSpin 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 "XTPSkinObjectSpin.h"
  23. #include "XTPSkinManager.h"
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char THIS_FILE[]=__FILE__;
  27. #define new DEBUG_NEW
  28. #endif
  29. #define UD_HITNOWHERE 0
  30. #define UD_HITDOWN 1
  31. #define UD_HITUP 2
  32. //////////////////////////////////////////////////////////////////////
  33. // Construction/Destruction
  34. //////////////////////////////////////////////////////////////////////
  35. IMPLEMENT_DYNCREATE(CXTPSkinObjectSpin, CXTPSkinObjectFrame)
  36. CXTPSkinObjectSpin::CXTPSkinObjectSpin()
  37. {
  38. m_strClassName = _T("SPIN");
  39. m_nHotButton = UD_HITNOWHERE;
  40. m_nPressedButton = UD_HITNOWHERE;
  41. }
  42. CXTPSkinObjectSpin::~CXTPSkinObjectSpin()
  43. {
  44. }
  45. BEGIN_MESSAGE_MAP(CXTPSkinObjectSpin, CXTPSkinObjectFrame)
  46. //{{AFX_MSG_MAP(CXTPSkinObjectSpin)
  47. ON_WM_ERASEBKGND()
  48. ON_WM_PAINT()
  49. ON_MESSAGE(WM_PRINTCLIENT, OnPrintClient)
  50. ON_WM_LBUTTONDOWN()
  51. ON_WM_LBUTTONUP()
  52. ON_WM_MOUSEMOVE()
  53. ON_MESSAGE_VOID(WM_MOUSELEAVE, OnMouseLeave)
  54. ON_WM_TIMER()
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CXTPSkinObjectSpin message handlers
  59. BOOL CXTPSkinObjectSpin::OnEraseBkgnd(CDC* /*pDC*/)
  60. {
  61. return TRUE;
  62. }
  63. UINT CXTPSkinObjectSpin::HitTest(CPoint pt)
  64. {
  65. CRect rc;
  66. GetClientRect(&rc);
  67. if (!rc.PtInRect(pt))
  68. return UD_HITNOWHERE;
  69. if (GetStyle() & UDS_HORZ)
  70. {
  71. // Horizontal placement
  72. if (pt.x < (rc.right / 2))
  73. {
  74. return UD_HITDOWN;
  75. }
  76. else if (pt.x > (rc.right / 2))
  77. {
  78. return UD_HITUP;
  79. }
  80. }
  81. else
  82. {
  83. if (pt.y > (rc.bottom / 2))
  84. {
  85. return UD_HITDOWN;
  86. }
  87. else if (pt.y < (rc.bottom / 2))
  88. {
  89. return UD_HITUP;
  90. }
  91. }
  92. return UD_HITNOWHERE;
  93. }
  94. LRESULT CXTPSkinObjectSpin::OnPrintClient(WPARAM wParam, LPARAM lParam)
  95. {
  96. if ((lParam & PRF_CLIENT) == 0)
  97. return Default();
  98. CDC* pDC = CDC::FromHandle((HDC)wParam);
  99. if (pDC) OnDraw(pDC);
  100. return 1;
  101. }
  102. void CXTPSkinObjectSpin::OnPaint()
  103. {
  104. CXTPSkinObjectPaintDC dc(this); // device context for painting
  105. OnDraw(&dc);
  106. }
  107. void CXTPSkinObjectSpin::OnDraw(CDC* pDC)
  108. {
  109. CRect rcClient;
  110. GetClientRect(&rcClient);
  111. CXTPBufferDC dcMem(*pDC, rcClient);
  112. dcMem.FillSolidRect(rcClient, GetColor(COLOR_3DFACE));
  113. DWORD dwStyle = GetStyle();
  114. int nLower = 0, nUpper = 0;
  115. SendMessage(UDM_GETRANGE32, (WPARAM) &nLower, (LPARAM) &nUpper);
  116. BOOL bEnabled = (nUpper != nLower) && IsWindowEnabled();
  117. CRect rcBtn = rcClient;
  118. CXTPSkinManagerClass* pClassSpin = GetSkinClass();
  119. HWND hWndBuddy = (HWND)SendMessage(UDM_GETBUDDY);
  120. if (hWndBuddy && GetWindowLong(hWndBuddy, GWL_EXSTYLE) & WS_EX_CLIENTEDGE)
  121. {
  122. if (dwStyle & UDS_ALIGNRIGHT)
  123. {
  124. rcBtn.DeflateRect(0, 1, 1, 1);
  125. CXTPSkinManagerClass* pClassEdit = GetSkinManager()->GetSkinClass(_T("EDIT"));
  126. COLORREF clrBorderColor = pClassEdit->GetThemeColor(0, 0, TMT_BORDERCOLOR);
  127. dcMem.Draw3dRect(rcClient, clrBorderColor, clrBorderColor);
  128. dcMem.FillSolidRect(rcClient.left, rcClient.top + 1, 1, rcClient.Height() - 2, GetColor(COLOR_WINDOW));
  129. }
  130. else if (dwStyle & UDS_ALIGNLEFT)
  131. {
  132. rcBtn.DeflateRect(1, 1, 0, 1);
  133. CXTPSkinManagerClass* pClassEdit = GetSkinManager()->GetSkinClass(_T("EDIT"));
  134. COLORREF clrBorderColor = pClassEdit->GetThemeColor(0, 0, TMT_BORDERCOLOR);
  135. dcMem.Draw3dRect(rcClient, clrBorderColor, clrBorderColor);
  136. dcMem.FillSolidRect(rcClient.right - 1, rcClient.top + 1, 1, rcClient.Height() - 2, GetColor(COLOR_WINDOW));
  137. }
  138. }
  139. RECT rc = rcBtn;
  140. if (dwStyle & UDS_HORZ)
  141. {
  142. int nState = DNHZS_NORMAL;
  143. if (!bEnabled)
  144. nState = DNHZS_DISABLED;
  145. else if (m_nPressedButton == UD_HITDOWN && m_nHotButton == UD_HITDOWN)
  146. nState = DNHZS_PRESSED;
  147. else if ((m_nHotButton == UD_HITDOWN || m_nPressedButton == UD_HITDOWN)  && (m_nPressedButton != UD_HITUP))
  148. nState = DNHZS_HOT;
  149. rc.right = (rcBtn.right + rcBtn.left) / 2;
  150. pClassSpin->DrawThemeBackground(&dcMem, SPNP_DOWNHORZ, nState, &rc);
  151. nState = UPHZS_NORMAL;
  152. if (!bEnabled)
  153. nState = UPHZS_DISABLED;
  154. else if (m_nPressedButton == UD_HITUP && m_nHotButton == UD_HITUP)
  155. nState = UPHZS_PRESSED;
  156. else if ((m_nHotButton == UD_HITUP || m_nPressedButton == UD_HITUP) && (m_nPressedButton != UD_HITDOWN))
  157. nState = UPHZS_HOT;
  158. rc.left = rcBtn.right - (rc.right - rc.left); // handles odd-x case, too
  159. rc.right = rcBtn.right;
  160. pClassSpin->DrawThemeBackground(&dcMem, SPNP_UPHORZ, nState, &rc);
  161. }
  162. else
  163. {
  164. int nState = UPS_NORMAL;
  165. if (!bEnabled)
  166. nState = UPS_DISABLED;
  167. else if (m_nPressedButton == UD_HITUP && m_nHotButton == UD_HITUP)
  168. nState = UPS_PRESSED;
  169. else if ((m_nHotButton == UD_HITUP || m_nPressedButton == UD_HITUP) && (m_nPressedButton != UD_HITDOWN))
  170. nState = UPS_HOT;
  171. rc.bottom = (rcBtn.bottom + rcBtn.top) / 2;
  172. pClassSpin->DrawThemeBackground(&dcMem, SPNP_UP, nState, &rc);
  173. nState = DNS_NORMAL;
  174. if (!bEnabled)
  175. nState = DNS_DISABLED;
  176. else if (m_nPressedButton == UD_HITDOWN && m_nHotButton == UD_HITDOWN)
  177. nState = DNS_PRESSED;
  178. else if ((m_nHotButton == UD_HITDOWN || m_nPressedButton == UD_HITDOWN)  && (m_nPressedButton != UD_HITUP))
  179. nState = DNS_HOT;
  180. rc.top = rcBtn.bottom - (rc.bottom - rc.top); // handles odd-y case, too
  181. rc.bottom = rcBtn.bottom;
  182. pClassSpin->DrawThemeBackground(&dcMem, SPNP_DOWN, nState, &rc);
  183. }
  184. }
  185. void CXTPSkinObjectSpin::OnMouseMove(UINT /*nFlags*/, CPoint point)
  186. {
  187. UINT uHot = HitTest(point);
  188. if (uHot != m_nHotButton)
  189. {
  190. m_nHotButton = uHot;
  191. Invalidate(FALSE);
  192. if (m_nHotButton != HTNOWHERE)
  193. {
  194. TRACKMOUSEEVENT tme = {sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd, HOVER_DEFAULT};
  195. _TrackMouseEvent(&tme);
  196. }
  197. }
  198. }
  199. void CXTPSkinObjectSpin::OnMouseLeave()
  200. {
  201. OnMouseMove(0, CPoint(-1, -1));
  202. }
  203. void CXTPSkinObjectSpin::OnLButtonDown(UINT nFlags, CPoint point)
  204. {
  205. CXTPSkinObjectFrame::OnLButtonDown(nFlags, point);
  206. UINT uHot = HitTest(point);
  207. if (uHot != HTNOWHERE)
  208. {
  209. m_nPressedButton = uHot;
  210. Invalidate(FALSE);
  211. }
  212. }
  213. void CXTPSkinObjectSpin::OnLButtonUp(UINT nFlags, CPoint point)
  214. {
  215. if (m_nPressedButton != HTNOWHERE)
  216. {
  217. m_nPressedButton = HTNOWHERE;
  218. Invalidate(FALSE);
  219. }
  220. CXTPSkinObjectFrame::OnLButtonUp(nFlags, point);
  221. }
  222. void CXTPSkinObjectSpin::OnTimer(UINT_PTR nIDEvent)
  223. {
  224. CXTPSkinObjectFrame::OnTimer(nIDEvent);
  225. }