PropertyGridItemNumber.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "StdAfx.h"
  2. #include "PropertyGridInplaceEdit.h"
  3. #include "PropertyGridInplaceButton.h"
  4. #include "PropertyGridInplaceList.h"
  5. #include "PropertyGridItem.h"
  6. #include "PropertyGridItemNumber.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CPropertyGridItemNumber
  9. CPropertyGridItemNumber::CPropertyGridItemNumber(CString strCaption, int nValue)
  10. : CPropertyGridItem(strCaption)
  11. {
  12. _Init();
  13. SetNumber(nValue);
  14. }
  15. CPropertyGridItemNumber::CPropertyGridItemNumber(UINT nID, int nValue)
  16. : CPropertyGridItem(nID)
  17. {
  18. _Init();
  19. SetNumber(nValue);
  20. }
  21. CPropertyGridItemNumber::~CPropertyGridItemNumber(void)
  22. {
  23. }
  24. /////////////////////////////////////////////////////////////////////////////
  25. //
  26. void CPropertyGridItemNumber::_Init()
  27. {
  28. m_pBindNumber = NULL;
  29. m_bHasMinValue = FALSE;
  30. m_bHasMaxValue = FALSE;
  31. m_nMinValue = 0;
  32. m_nMaxValue = 0;
  33. }
  34. void CPropertyGridItemNumber::SetValue(CString strValue)
  35. {
  36. SetNumber(_ttol(strValue));
  37. }
  38. void CPropertyGridItemNumber::SetNumber(int nValue)
  39. {
  40. m_nValue = nValue;
  41. if (m_bHasMinValue && m_nValue < m_nMinValue)
  42. m_nValue = m_nMinValue;
  43. if (m_bHasMaxValue && m_nValue > m_nMaxValue)
  44. m_nValue = m_nMaxValue;
  45. CString strValue;
  46. strValue.Format(_T("%i"), m_nValue);
  47. CPropertyGridItem::SetValue(strValue);
  48. if (m_pBindNumber)
  49. *m_pBindNumber = m_nValue;
  50. }
  51. void CPropertyGridItemNumber::SetMinNumber(int nMinValue)
  52. {
  53. m_bHasMinValue = TRUE;
  54. m_nMinValue = nMinValue;
  55. if (m_nValue < m_nMinValue)
  56. SetNumber(m_nMinValue);
  57. }
  58. void CPropertyGridItemNumber::SetMaxNumber(int nMaxValue)
  59. {
  60. m_bHasMaxValue = TRUE;
  61. m_nMaxValue = nMaxValue;
  62. if (m_nValue > m_nMaxValue)
  63. SetNumber(m_nMaxValue);
  64. }