SPPPropertyGridItemNumber.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #include "StdAfx.h"
  7. #include "SPVC80Helpers.h"
  8. #include "SPPropertyGridInplaceEdit.h"
  9. #include "SPPropertyGridInplaceButton.h"
  10. #include "SPPropertyGridInplaceList.h"
  11. #include "SPPropertyGridItem.h"
  12. #include "SPPropertyGridItemNumber.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CSPPropertyGridItemNumber
  20. IMPLEMENT_DYNAMIC( CSPPropertyGridItemNumber , CSPPropertyGridItem )
  21. CSPPropertyGridItemNumber::CSPPropertyGridItemNumber( CString strCaption , long nValue , long * pBindNumber ) : CSPPropertyGridItem( strCaption )
  22. {
  23. m_pBindNumber = pBindNumber;
  24. SetNumber( nValue );
  25. }
  26. CSPPropertyGridItemNumber::CSPPropertyGridItemNumber( UINT nID , long nValue , long * pBindNumber ) : CSPPropertyGridItem( nID )
  27. {
  28. m_pBindNumber = pBindNumber;
  29. SetNumber( nValue );
  30. }
  31. CSPPropertyGridItemNumber::~CSPPropertyGridItemNumber()
  32. {
  33. }
  34. /////////////////////////////////////////////////////////////////////////////
  35. //
  36. void CSPPropertyGridItemNumber::SetValue( CString strValue )
  37. {
  38. SetNumber( _ttol( strValue ) );
  39. }
  40. void CSPPropertyGridItemNumber::SetNumber( long nValue )
  41. {
  42. m_nValue = nValue;
  43. if ( m_pBindNumber )
  44. {
  45. *m_pBindNumber = m_nValue;
  46. }
  47. CString strValue;
  48. strValue.Format( _T( "%i" ),nValue );
  49. CSPPropertyGridItem::SetValue( strValue );
  50. }
  51. void CSPPropertyGridItemNumber::BindToNumber( long * pBindNumber )
  52. {
  53. m_pBindNumber = pBindNumber;
  54. if ( m_pBindNumber )
  55. {
  56. *m_pBindNumber = m_nValue;
  57. }
  58. }
  59. void CSPPropertyGridItemNumber::OnBeforeInsert()
  60. {
  61. if ( m_pBindNumber && *m_pBindNumber != m_nValue )
  62. {
  63. SetNumber( *m_pBindNumber );
  64. }
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CSPPropertyGridItemDouble
  68. IMPLEMENT_DYNAMIC( CSPPropertyGridItemDouble , CSPPropertyGridItem )
  69. CSPPropertyGridItemDouble::CSPPropertyGridItemDouble( CString strCaption , double fValue , LPCTSTR strFormat , double * pBindDouble ) : CSPPropertyGridItem( strCaption )
  70. {
  71. m_pBindDouble = pBindDouble;
  72. m_strFormat = strFormat;
  73. SetDouble( fValue );
  74. }
  75. CSPPropertyGridItemDouble::CSPPropertyGridItemDouble( UINT nID , double fValue , LPCTSTR strFormat , double * pBindDouble ) : CSPPropertyGridItem( nID )
  76. {
  77. m_pBindDouble = pBindDouble;
  78. m_strFormat = strFormat;
  79. SetDouble( fValue );
  80. }
  81. CSPPropertyGridItemDouble::~CSPPropertyGridItemDouble()
  82. {
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. //
  86. void CSPPropertyGridItemDouble::SetValue( CString strValue )
  87. {
  88. #ifdef _UNICODE
  89. char astring[20];
  90. WideCharToMultiByte( CP_ACP,0,strValue,-1,astring,20,NULL,NULL );
  91. SetDouble( ( double ) atof( astring ) );
  92. #else
  93. SetDouble( ( double ) atof( strValue ) );
  94. #endif
  95. }
  96. void CSPPropertyGridItemDouble::SetDouble( double fValue )
  97. {
  98. m_fValue = fValue;
  99. if ( m_pBindDouble )
  100. {
  101. *m_pBindDouble = m_fValue;
  102. }
  103. CString strValue;
  104. strValue.Format( m_strFormat,fValue );
  105. CSPPropertyGridItem::SetValue( strValue );
  106. }
  107. void CSPPropertyGridItemDouble::BindToDouble( double * pBindNumber )
  108. {
  109. m_pBindDouble = pBindNumber;
  110. if ( m_pBindDouble )
  111. {
  112. *m_pBindDouble = m_fValue;
  113. }
  114. }
  115. void CSPPropertyGridItemDouble::OnBeforeInsert()
  116. {
  117. if ( m_pBindDouble && *m_pBindDouble != m_fValue )
  118. {
  119. SetDouble( *m_pBindDouble );
  120. }
  121. }