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

对话框与窗口

开发平台:

Visual C++

  1. // XTPControlProgress.cpp : implementation of the CXTPControlProgress 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 "Common/XTPColorManager.h"
  23. #include "Common/XTPPropExchange.h"
  24. #include "XTPControlProgress.h"
  25. #include "XTPPaintManager.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. CXTPProgressBase::CXTPProgressBase()
  32. {
  33. m_nMin = 0;
  34. m_nMax = 100;
  35. m_nPos = 0;
  36. }
  37. CXTPProgressBase::~CXTPProgressBase()
  38. {
  39. }
  40. void CXTPProgressBase::GetRange(int& nLower, int& nUpper) const
  41. {
  42. nLower = m_nMin;
  43. nUpper = m_nMax;
  44. }
  45. void CXTPProgressBase::SetRange(int nLower, int nUpper)
  46. {
  47. if (m_nMin != nLower || m_nMax != nUpper)
  48. {
  49. m_nMin = nLower;
  50. m_nMax = nUpper;
  51. RedrawProgress();
  52. }
  53. }
  54. void CXTPProgressBase::SetPos(int nPos)
  55. {
  56. if (nPos < m_nMin) nPos = m_nMin;
  57. if (nPos > m_nMax) nPos = m_nMax;
  58. if (m_nPos != nPos)
  59. {
  60. m_nPos = nPos;
  61. RedrawProgress();
  62. }
  63. }
  64. IMPLEMENT_XTP_CONTROL(CXTPControlProgress, CXTPControl)
  65. CXTPControlProgress::CXTPControlProgress()
  66. {
  67. m_nWidth = 100;
  68. }
  69. CSize CXTPControlProgress::GetSize(CDC* /*pDC*/)
  70. {
  71. return CSize(m_nWidth, m_nHeight > 0 ? m_nHeight : GetProgressPaintManager()->m_cyProgress);
  72. }
  73. void CXTPControlProgress::Draw(CDC* pDC)
  74. {
  75. GetProgressPaintManager()->DrawProgress(pDC, this);
  76. }
  77. void CXTPControlProgress::RedrawProgress()
  78. {
  79. RedrawParent(FALSE);
  80. }
  81. CXTPProgressPaintManager* CXTPControlProgress::GetProgressPaintManager() const
  82. {
  83. return GetPaintManager()->GetProgressPaintManager();
  84. }
  85. CRect CXTPControlProgress::GetProgressRect()
  86. {
  87. return GetRect();
  88. }
  89. void CXTPControlProgress::Copy(CXTPControl* pControl, BOOL bRecursive)
  90. {
  91. CXTPControl::Copy(pControl, bRecursive);
  92. CXTPControlProgress* pControlProgress = DYNAMIC_DOWNCAST(CXTPControlProgress, pControl);
  93. if (!pControlProgress)
  94. return;
  95. SetRange(pControlProgress->m_nMin, pControlProgress->m_nMax);
  96. SetPos(pControlProgress->GetPos());
  97. }
  98. void CXTPControlProgress::DoPropExchange(CXTPPropExchange* pPX)
  99. {
  100. CXTPControl::DoPropExchange(pPX);
  101. PX_Int(pPX, _T("Min"), m_nMin, 0);
  102. PX_Int(pPX, _T("Max"), m_nMax, 100);
  103. PX_Int(pPX, _T("Pos"), m_nPos, 0);
  104. }
  105. //////////////////////////////////////////////////////////////////////////
  106. // CXTPProgressPaintManager
  107. CXTPProgressPaintManager::CXTPProgressPaintManager(CXTPPaintManager* pPaintManager)
  108. {
  109. m_pPaintManager = pPaintManager;
  110. m_cyProgress = 16;
  111. }
  112. CXTPProgressPaintManager::~CXTPProgressPaintManager()
  113. {
  114. }
  115. void CXTPProgressPaintManager::RefreshMetrics()
  116. {
  117. m_themeProgress.OpenTheme(0, L"PROGRESS");
  118. }
  119. void CXTPProgressPaintManager::DrawProgress(CDC* pDC, CXTPProgressBase* pProgressBar)
  120. {
  121. CRect rc(pProgressBar->GetProgressRect());
  122. XTPPaintTheme theme = GetPaintManager()->BaseTheme();
  123. BOOL bThemed = (theme != xtpThemeOffice2000) && (theme != xtpThemeOfficeXP) && m_themeProgress.IsAppThemed();
  124. BOOL bVertical = FALSE;
  125. int nLower, nUpper, nPos;
  126. pProgressBar->GetRange(nLower, nUpper);
  127. nPos = pProgressBar->GetPos();
  128. int nWidth, dxBlock;
  129. CRect rcClient(rc);
  130. if (!bThemed)
  131. rcClient.DeflateRect(2, 2);
  132. else if (bVertical)
  133. rcClient.DeflateRect(3, 4);
  134. else
  135. rcClient.DeflateRect(4, 3);
  136. if (bVertical)
  137. {
  138. nWidth = rcClient.bottom - rcClient.top;
  139. dxBlock = (rcClient.right - rcClient.left) * 2 / 3;
  140. }
  141. else
  142. {
  143. nWidth = rcClient.right - rcClient.left;
  144. dxBlock = (rcClient.bottom - rcClient.top) * 2 / 3;
  145. }
  146. int x = MulDiv(nWidth, nPos - nLower, nUpper - nLower);
  147. if (!bThemed)
  148. {
  149. pDC->FillSolidRect(rc, GetXtremeColor(COLOR_BTNFACE));
  150. pDC->Draw3dRect(rc, GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DSHADOW));
  151. if (rcClient.Width() < 2)
  152. return;
  153. pDC->FillSolidRect(rcClient.left, rcClient.top, x, rcClient.Height(), GetXtremeColor(COLOR_HIGHLIGHT));
  154. }
  155. else
  156. {
  157. m_themeProgress.DrawThemeBackground(*pDC, bVertical ? PP_BARVERT : PP_BAR, 0, rc, NULL);
  158. int dxSpace = 2;
  159. if (bThemed)
  160. {
  161. m_themeProgress.GetThemeInt(0, 0, TMT_PROGRESSCHUNKSIZE, &dxBlock);
  162. m_themeProgress.GetThemeInt(0, 0, TMT_PROGRESSSPACESIZE, &dxSpace);
  163. }
  164. rc = rcClient;
  165. if (dxBlock == 0)
  166. dxBlock = 1;    // avoid div by zero
  167. int nBlocks = (x + (dxBlock + dxSpace) - 1) / (dxBlock + dxSpace); // round up
  168. for (int i = 0; i < nBlocks; i++)
  169. {
  170. if (bVertical)
  171. {
  172. rc.top = rc.bottom - dxBlock;
  173. // are we past the end?
  174. if (rc.bottom <= rcClient.top)
  175. break;
  176. if (rc.top <= rcClient.top)
  177. rc.top = rcClient.top + 1;
  178. }
  179. else
  180. {
  181. rc.right = rc.left + dxBlock;
  182. // are we past the end?
  183. if (rc.left >= rcClient.right)
  184. break;
  185. if (rc.right >= rcClient.right)
  186. rc.right = rcClient.right - 1;
  187. }
  188. m_themeProgress.DrawThemeBackground(*pDC, bVertical ? PP_CHUNKVERT : PP_CHUNK, 0, rc, NULL);
  189. if (bVertical)
  190. {
  191. rc.bottom = rc.top - dxSpace;
  192. }
  193. else
  194. {
  195. rc.left = rc.right + dxSpace;
  196. }
  197. }
  198. }
  199. }