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

对话框与窗口

开发平台:

Visual C++

  1. // XTPControlSlider.cpp : implementation of the CXTPControlSlider 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/XTPPropExchange.h"
  23. #include "XTPControlSlider.h"
  24. #include "XTPPaintManager.h"
  25. #include "XTPCommandBar.h"
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char THIS_FILE[]=__FILE__;
  29. #define new DEBUG_NEW
  30. #endif
  31. //////////////////////////////////////////////////////////////////////
  32. // Construction/Destruction
  33. //////////////////////////////////////////////////////////////////////
  34. IMPLEMENT_XTP_CONTROL(CXTPControlSlider, CXTPControl)
  35. CXTPControlSlider::CXTPControlSlider()
  36. {
  37. m_nWidth = 150;
  38. m_pSliderCtrl = new CXTPControlSliderCtrl;
  39. m_pSliderCtrl->m_pControl = this;
  40. m_nMax = 100;
  41. m_nMin = 0;
  42. m_nPos = 0;
  43. m_rcPadding.SetRect(2, 2, 2, 2);
  44. m_dwSliderStyle = TBS_BOTH | TBS_NOTICKS;
  45. }
  46. CXTPControlSlider::~CXTPControlSlider()
  47. {
  48. delete m_pSliderCtrl;
  49. }
  50. DWORD CXTPControlSlider::GetSliderStyle() const
  51. {
  52. return m_dwSliderStyle;
  53. }
  54. void CXTPControlSlider::SetSliderStyle(DWORD dwStyle)
  55. {
  56. m_dwSliderStyle = dwStyle;
  57. }
  58. void CXTPControlSlider::Copy(CXTPControl* pControl, BOOL bRecursive)
  59. {
  60. CXTPControl::Copy(pControl, bRecursive);
  61. CXTPControlSlider* pControlSlider = DYNAMIC_DOWNCAST(CXTPControlSlider, pControl);
  62. if (!pControlSlider)
  63. return;
  64. SetRange(pControlSlider->m_nMin, pControlSlider->m_nMax);
  65. SetPos(pControlSlider->GetPos());
  66. m_dwSliderStyle = pControlSlider->m_dwSliderStyle;
  67. }
  68. void CXTPControlSlider::DoPropExchange(CXTPPropExchange* pPX)
  69. {
  70. CXTPControl::DoPropExchange(pPX);
  71. PX_Int(pPX, _T("Min"), m_nMin, 0);
  72. PX_Int(pPX, _T("Max"), m_nMax, 100);
  73. PX_Int(pPX, _T("Pos"), m_nPos, 0);
  74. if (pPX->GetSchema() > _XTP_SCHEMA_1121)
  75. {
  76. PX_DWord(pPX, _T("SliderStyle"), m_dwSliderStyle, TBS_BOTH | TBS_NOTICKS);
  77. }
  78. }
  79. CSize CXTPControlSlider::GetSize(CDC* /*pDC*/)
  80. {
  81. int nButtonHeight = GetPaintManager()->GetControlHeight();
  82. if (m_pSliderCtrl->GetSafeHwnd() && m_pSliderCtrl->GetStyle() & TBS_VERT)
  83. {
  84. return CSize(nButtonHeight, GetWidth());
  85. }
  86. return CSize(GetWidth(), nButtonHeight);
  87. }
  88. void CXTPControlSlider::Draw(CDC* /*pDC*/)
  89. {
  90. }
  91. void CXTPControlSlider::SetRect(CRect rcControl)
  92. {
  93. if (m_rcControl == rcControl && !(m_pSliderCtrl && !m_pSliderCtrl->GetSafeHwnd()))
  94. {
  95. if (!(m_pSliderCtrl && m_pSliderCtrl->GetSafeHwnd() && m_pSliderCtrl->GetParent() != m_pParent))
  96. return;
  97. }
  98. if (m_pSliderCtrl && m_pSliderCtrl->GetSafeHwnd() && m_pSliderCtrl->GetParent() != m_pParent)
  99. {
  100. m_pSliderCtrl->DestroyWindow();
  101. }
  102. m_rcControl = rcControl;
  103. if (m_pSliderCtrl)
  104. {
  105. if (!m_pSliderCtrl->GetSafeHwnd())
  106. {
  107. m_pSliderCtrl->Create(WS_CHILD | m_dwSliderStyle, CRect(0, 0, 0, 0), m_pParent, 0);
  108. m_pSliderCtrl->SetRange(m_nMin, m_nMax);
  109. m_pSliderCtrl->SetPos(m_nPos);
  110. }
  111. rcControl.DeflateRect(m_rcPadding);
  112. if (m_pParent->GetType() == xtpBarTypePopup && m_pParent->GetPosition() == xtpBarPopup)
  113. {
  114. CXTPPaintManager* pPaintManager = GetPaintManager();
  115. rcControl.left += pPaintManager->GetPopupBarGripperWidth(GetParent())
  116. + pPaintManager->m_nPopupBarTextPadding - 2;
  117. }
  118. m_pSliderCtrl->MoveWindow(rcControl);
  119. m_pSliderCtrl->SetWindowPos(0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | ((m_dwHideFlags != xtpNoHide) ? SWP_HIDEWINDOW : SWP_SHOWWINDOW));
  120. m_pSliderCtrl->EnableWindow(m_bEnabled);
  121. m_pSliderCtrl->Invalidate(FALSE);
  122. }
  123. }
  124. void CXTPControlSlider::SetPos(int nPos)
  125. {
  126. if (m_pSliderCtrl->GetSafeHwnd() && ::GetCapture() == m_pSliderCtrl->GetSafeHwnd())
  127. return;
  128. m_nPos = nPos;
  129. if (m_pSliderCtrl->GetSafeHwnd())
  130. {
  131. m_pSliderCtrl->SetPos(nPos);
  132. }
  133. }
  134. int CXTPControlSlider::GetPos()
  135. {
  136. if (m_pSliderCtrl->GetSafeHwnd())
  137. {
  138. return m_nPos = m_pSliderCtrl->GetPos();
  139. }
  140. return m_nPos;
  141. }
  142. void CXTPControlSlider::SetRange( int nMin, int nMax)
  143. {
  144. m_nMin = nMin;
  145. m_nMax = nMax;
  146. if (m_pSliderCtrl->GetSafeHwnd())
  147. {
  148. m_pSliderCtrl->SetRange(nMin, nMax);
  149. }
  150. }
  151. BOOL CXTPControlSlider::HasFocus() const
  152. {
  153. return ::GetCapture() == m_pSliderCtrl->GetSafeHwnd();
  154. }
  155. void CXTPControlSlider::SetEnabled(BOOL bEnabled)
  156. {
  157. if (bEnabled != m_bEnabled)
  158. {
  159. m_bEnabled = bEnabled;
  160. if (m_pSliderCtrl && m_pSliderCtrl->GetSafeHwnd())
  161. m_pSliderCtrl->EnableWindow(bEnabled);
  162. DelayRedrawParent();
  163. }
  164. }
  165. void CXTPControlSlider::SetParent(CXTPCommandBar* pParent)
  166. {
  167. CXTPControl::SetParent(pParent);
  168. if (!pParent && m_pSliderCtrl && m_pSliderCtrl->GetSafeHwnd())
  169. {
  170. m_pSliderCtrl->DestroyWindow();
  171. }
  172. }
  173. void CXTPControlSlider::SetHideFlags(DWORD dwFlags)
  174. {
  175. if (m_dwHideFlags != dwFlags)
  176. {
  177. m_dwHideFlags = dwFlags;
  178. if (m_pSliderCtrl && m_pSliderCtrl->GetSafeHwnd())
  179. m_pSliderCtrl->SetWindowPos(0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | ((m_dwHideFlags != xtpNoHide) ? SWP_HIDEWINDOW : SWP_SHOWWINDOW));
  180. DelayLayoutParent();
  181. }
  182. }
  183. void CXTPControlSlider::OnCalcDynamicSize(DWORD dwMode)
  184. {
  185. if (m_pSliderCtrl->GetSafeHwnd())
  186. {
  187. if (dwMode & LM_VERTDOCK) m_pSliderCtrl->ModifyStyle(0, TBS_VERT);
  188. else m_pSliderCtrl->ModifyStyle(TBS_VERT, 0);
  189. }
  190. }
  191. void CXTPControlSlider::OnClick(BOOL bKeyboard, CPoint pt)
  192. {
  193. if (IsCustomizeMode() && !bKeyboard)
  194. {
  195. m_pParent->SetPopuped(-1);
  196. m_pParent->SetSelected(-1);
  197. CustomizeStartDrag(pt);
  198. }
  199. else
  200. {
  201. }
  202. }
  203. void CXTPControlSlider::OnScroll(UINT nSBCode, UINT /*nPos*/)
  204. {
  205. if (nSBCode != SB_ENDSCROLL)
  206. {
  207. m_nPos = GetPos();
  208. NotifySite(CBN_XTP_EXECUTE);
  209. }
  210. }
  211. void CXTPControlSlider::OnThemeChanged()
  212. {
  213. if (m_pSliderCtrl->GetSafeHwnd())
  214. m_pSliderCtrl->Invalidate(FALSE);
  215. }
  216. BEGIN_MESSAGE_MAP(CXTPControlSliderCtrl, CSliderCtrl)
  217. ON_WM_ERASEBKGND()
  218. ON_WM_CTLCOLOR_REFLECT()
  219. ON_WM_LBUTTONDOWN()
  220. ON_WM_RBUTTONDOWN()
  221. ON_WM_MOUSEMOVE()
  222. ON_WM_HSCROLL_REFLECT()
  223. ON_WM_VSCROLL_REFLECT()
  224. END_MESSAGE_MAP()
  225. BOOL CXTPControlSliderCtrl::OnEraseBkgnd(CDC* /*pDC*/)
  226. {
  227. return TRUE;
  228. }
  229. HBRUSH CXTPControlSliderCtrl::CtlColor ( CDC* pDC, UINT /*nCtlColor*/ )
  230. {
  231. if (pDC->m_hAttribDC == NULL) pDC->m_hAttribDC = pDC->m_hDC;
  232. CXTPWindowRect rcOrig(this);
  233. GetParent()->ScreenToClient(&rcOrig);
  234. CPoint pt = pDC->SetViewportOrg(-rcOrig.TopLeft());
  235. ((CXTPCommandBar*)GetParent())->DrawCommandBar(pDC, rcOrig);
  236. pDC->SetViewportOrg(pt);
  237. SendMessage(TBM_CLEARSEL, 0, 0); // minor hacking. don't ask me why
  238. return (HBRUSH)GetStockObject(NULL_BRUSH);
  239. }
  240. void CXTPControlSliderCtrl::OnLButtonDown(UINT nFlags, CPoint point)
  241. {
  242. if (m_pControl->IsCustomizeMode())
  243. {
  244. if (m_pControl->GetParent()->IsCustomizable() && ((m_pControl->GetFlags() & xtpFlagNoMovable) == 0))
  245. m_pControl->OnClick();
  246. }
  247. else CSliderCtrl::OnLButtonDown(nFlags, point);
  248. }
  249. void CXTPControlSliderCtrl::OnRButtonDown(UINT nFlags, CPoint point)
  250. {
  251. if (m_pControl->IsCustomizeMode())
  252. {
  253. ClientToScreen(&point);
  254. m_pControl->GetParent()->ScreenToClient(&point);
  255. m_pControl->GetParent()->OnRButtonDown(nFlags, point);
  256. return;
  257. }
  258. CSliderCtrl::OnRButtonDown(nFlags, point);
  259. }
  260. void CXTPControlSliderCtrl::OnMouseMove(UINT nFlags, CPoint point)
  261. {
  262. CSliderCtrl::OnMouseMove(nFlags, point);
  263. MapWindowPoints(m_pControl->GetParent(), &point, 1);
  264. m_pControl->GetParent()->OnMouseMove(nFlags, point);
  265. }
  266. void CXTPControlSliderCtrl::HScroll(UINT nSBCode, UINT nPos)
  267. {
  268. m_pControl->OnScroll(nSBCode, nPos);
  269. }
  270. void CXTPControlSliderCtrl::VScroll(UINT nSBCode, UINT nPos)
  271. {
  272. m_pControl->OnScroll(nSBCode, nPos);
  273. }