SPPropertyGridItemNumber.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #if !defined(__SPPROPERTYGRIDITEMNUMBER_H__)
  7. #define __SPPROPERTYGRIDITEMNUMBER_H__
  8. #if _MSC_VER > 1000
  9. #pragma once
  10. #endif // _MSC_VER > 1000
  11. //===========================================================================
  12. // Summary:
  13. // CSPPropertyGridItemNumber is a CSPPropertyGridItem derived class.
  14. // It is used to create an integer value item in a Property Grid control.
  15. //===========================================================================
  16. class CSPPropertyGridItemNumber : public CSPPropertyGridItem
  17. {
  18. public:
  19. //-----------------------------------------------------------------------
  20. // Summary:
  21. // Constructs a CSPPropertyGridItemNumber object
  22. // Parameters:
  23. // strCaption - Caption of the item.
  24. // nID - Identifier of the item.
  25. // nValue - Initial value of item.
  26. // pBindNumber - If not NULL, then the value of this item
  27. // is bound the value of this variable.
  28. // Remarks:
  29. // Class CSPPropertyGridItemNumber has no default constructor.
  30. //
  31. // When using the second constructor, the Identifier (nID) of the
  32. // second constructor can be linked with a STRINGTABLE resource
  33. // with the same id in such form "Caption\\nDescription".
  34. //
  35. // BINDING:
  36. // Variables can be bound to an item in two ways, the first is
  37. // to pass in a variable at the time of creation, the second allows
  38. // variables to be bound to an item after creation with the
  39. // BindToNumber member.
  40. //
  41. // Bound variables store the values of the property grid items
  42. // and can be accessed without using the property grid methods
  43. // and properties. Bound variables allow the property grid to
  44. // store data in variables. When the value of a PropertyGridItem
  45. // is changed, the value of the bound variable will be changed to
  46. // the PropertyGridItem value. The advantage of binding is that
  47. // the variable can be used and manipulated without using
  48. // PropertyGridItem methods and properties.
  49. //
  50. // NOTE: If the value of the variable is changed without using
  51. // the PropertyGrid, the PropertyGridItem value will not be
  52. // updated until you call CSPPropertyGrid::Refresh.
  53. // See Also: BindToNumber
  54. //-----------------------------------------------------------------------
  55. CSPPropertyGridItemNumber( CString strCaption , long nValue = 0 , long * pBindNumber = NULL );
  56. CSPPropertyGridItemNumber( UINT nID , long nValue = 0 , long * pBindNumber = NULL ); // <COMBINE CSPPropertyGridItemNumber::CSPPropertyGridItemNumber@CString@long@long*>
  57. //-----------------------------------------------------------------------
  58. // Summary:
  59. // Destroys a CSPPropertyGridItemNumber object
  60. //-----------------------------------------------------------------------
  61. virtual ~CSPPropertyGridItemNumber();
  62. public:
  63. //-----------------------------------------------------------------------
  64. // Summary:
  65. // Call this method to change the item's value.
  66. // Parameters:
  67. // nValue - The new integer value of the item.
  68. //-----------------------------------------------------------------------
  69. void SetNumber( long nValue );
  70. //-----------------------------------------------------------------------
  71. // Summary:
  72. // Call this method to get the integer value of the item.
  73. // Returns:
  74. // The integer value of the item.
  75. //-----------------------------------------------------------------------
  76. long GetNumber();
  77. //-----------------------------------------------------------------------
  78. // Summary:
  79. // Call this method to bind an item to a long value.
  80. // Parameters:
  81. // pBindNumber - Long value to bind to item.
  82. // Remarks:
  83. // Variables can be bound to an item in two ways, the first is
  84. // to pass in a variable at the time of creation, the second allows
  85. // variables to be bound to an item after creation with the
  86. // BindToNumber member.
  87. //
  88. // Bound variables store the values of the property grid items
  89. // and can be accessed without using the property grid methods
  90. // and properties. Bound variables allow the property grid to
  91. // store data in variables. When the value of a PropertyGridItem
  92. // is changed, the value of the bound variable will be changed to
  93. // the PropertyGridItem value. The advantage of binding is that
  94. // the variable can be used and manipulated without using
  95. // PropertyGridItem methods and properties.
  96. //
  97. // NOTE: If the value of the variable is changed without using
  98. // the PropertyGrid, the PropertyGridItem value will not be
  99. // updated until you call CSPPropertyGrid::Refresh.
  100. //-----------------------------------------------------------------------
  101. void BindToNumber( long * pBindNumber );
  102. protected:
  103. //-----------------------------------------------------------------------
  104. // Summary:
  105. // Call this method to change an item's value.
  106. // Override this method to add new functionality.
  107. // You should call the base class version of this function from your
  108. // override.
  109. // Parameters:
  110. // strValue - New value of the item.
  111. //-----------------------------------------------------------------------
  112. virtual void SetValue( CString strValue );
  113. //-------------------------------------------------------------------------
  114. // Summary:
  115. // This member is called before the item becomes visible in the
  116. // property grid.
  117. // Remarks:
  118. // Before the item is inserted, it is first check to see if it
  119. // is bound to a variable, if it is, then the value of the item
  120. // is updated with the value stored in the bound variable.
  121. //
  122. // OnBeforeInsert is called when an item is inserted,
  123. // when a category is inserted, when a category or item is
  124. // expanded, and when the sort property has changed.
  125. //-------------------------------------------------------------------------
  126. virtual void OnBeforeInsert();
  127. protected:
  128. long m_nValue; // Value of the item.
  129. long * m_pBindNumber; // Binded object. This is a pointer to the variable bound to this item.
  130. private:
  131. DECLARE_DYNAMIC( CSPPropertyGridItemNumber )
  132. };
  133. //===========================================================================
  134. // Summary:
  135. // CSPPropertyGridItemDouble is a CSPPropertyGridItem derived class.
  136. // It is used to create an double value item in a Property Grid control.
  137. //===========================================================================
  138. class CSPPropertyGridItemDouble : public CSPPropertyGridItem
  139. {
  140. public:
  141. //-----------------------------------------------------------------------
  142. // Summary:
  143. // Constructs a CSPPropertyGridItemDouble object.
  144. // Parameters:
  145. // strCaption - Caption of the item.
  146. // nID - Identifier of the item.
  147. // fValue - Initial value.
  148. // strFormat - The number of digits after the decimal point.
  149. // For example "%0.5f" would display 5 digits
  150. // past the decimal place.
  151. // pBindNumber - If not NULL, then the value of this item
  152. // is bound the value of this variable.
  153. // Remarks:
  154. // Class CSPPropertyGridItemDouble has no default constructor.
  155. //
  156. // When using the second constructor, the Identifier (nID) of the
  157. // second constructor can be linked with a STRINGTABLE resource
  158. // with the same id in such form "Caption\\nDescription".
  159. //
  160. // BINDING:
  161. // Variables can be bound to an item in two ways, the first is
  162. // to pass in a variable at the time of creation, the second allows
  163. // variables to be bound to an item after creation with the
  164. // BindToDouble member.
  165. //
  166. // Bound variables store the values of the property grid items
  167. // and can be accessed without using the property grid methods
  168. // and properties. Bound variables allow the property grid to
  169. // store data in variables. When the value of a PropertyGridItem
  170. // is changed, the value of the bound variable will be changed to
  171. // the PropertyGridItem value. The advantage of binding is that
  172. // the variable can be used and manipulated without using
  173. // PropertyGridItem methods and properties.
  174. //
  175. // NOTE: If the value of the variable is changed without using
  176. // the PropertyGrid, the PropertyGridItem value will not be
  177. // updated until you call CSPPropertyGrid::Refresh.
  178. // See Also: BindToDouble
  179. //-----------------------------------------------------------------------
  180. CSPPropertyGridItemDouble( CString strCaption , double fValue = 0 , LPCTSTR strFormat = _T( "%0.2f" ) , double * pBindNumber = NULL );
  181. CSPPropertyGridItemDouble( UINT nID , double fValue = 0 , LPCTSTR strFormat = _T( "%0.2f" ) , double * pBindNumber = NULL ); // <COMBINE CSPPropertyGridItemDouble::CSPPropertyGridItemDouble@CString@double@LPCTSTR@double*>
  182. //-----------------------------------------------------------------------
  183. // Summary:
  184. // Destroys a CSPPropertyGridItemDouble object.
  185. //-----------------------------------------------------------------------
  186. virtual ~CSPPropertyGridItemDouble();
  187. public:
  188. //-----------------------------------------------------------------------
  189. // Summary:
  190. // Call this method to change the item's value.
  191. // Parameters:
  192. // fValue - The new double value of the item.
  193. //-----------------------------------------------------------------------
  194. void SetDouble( double fValue );
  195. //-----------------------------------------------------------------------
  196. // Summary:
  197. // Call this method to get the double value of the item.
  198. // Returns:
  199. // The double value of the item.
  200. //-----------------------------------------------------------------------
  201. double GetDouble();
  202. //-----------------------------------------------------------------------
  203. // Summary:
  204. // Call this method to bind the item to a double value.
  205. // Parameters:
  206. // pBindDouble - Double value to bind to item.
  207. // Remarks:
  208. // Variables can be bound to an item in two ways, the first is
  209. // to pass in a variable at the time of creation, the second allows
  210. // variables to be bound to an item after creation with the
  211. // BindToDouble member.
  212. //
  213. // Bound variables store the values of the property grid items
  214. // and can be accessed without using the property grid methods
  215. // and properties. Bound variables allow the property grid to
  216. // store data in variables. When the value of a PropertyGridItem
  217. // is changed, the value of the bound variable will be changed to
  218. // the PropertyGridItem value. The advantage of binding is that
  219. // the variable can be used and manipulated without using
  220. // PropertyGridItem methods and properties.
  221. //
  222. // NOTE: If the value of the variable is changed without using
  223. // the PropertyGrid, the PropertyGridItem value will not be
  224. // updated until you call CSPPropertyGrid::Refresh.
  225. //-----------------------------------------------------------------------
  226. void BindToDouble( double * pBindDouble );
  227. protected:
  228. //-----------------------------------------------------------------------
  229. // Summary:
  230. // Call this method to change an item's value.
  231. // Override this method to add new functionality.
  232. // You should call the base class version of this function from your
  233. // override.
  234. // Parameters:
  235. // strValue - New value of the item.
  236. //-----------------------------------------------------------------------
  237. virtual void SetValue( CString strValue );
  238. //-------------------------------------------------------------------------
  239. // Summary:
  240. // This member is called before the item becomes visible in the
  241. // property grid.
  242. // Remarks:
  243. // Before the item is inserted, it is first check to see if it
  244. // is bound to a variable, if it is, then the value of the item
  245. // is updated with the value stored in the bound variable.
  246. //
  247. // OnBeforeInsert is called when an item is inserted,
  248. // when a category is inserted, when a category or item is
  249. // expanded, and when the sort property has changed.
  250. //-------------------------------------------------------------------------
  251. void OnBeforeInsert();
  252. protected:
  253. double m_fValue; // Double value of item.
  254. double * m_pBindDouble; // Binded value. This is a pointer to the variable bound to this item.
  255. private:
  256. DECLARE_DYNAMIC( CSPPropertyGridItemDouble )
  257. };
  258. //////////////////////////////////////////////////////////////////////
  259. AFX_INLINE long CSPPropertyGridItemNumber::GetNumber()
  260. {
  261. return m_nValue;
  262. }
  263. //////////////////////////////////////////////////////////////////////
  264. AFX_INLINE double CSPPropertyGridItemDouble::GetDouble()
  265. {
  266. return m_fValue;
  267. }
  268. #endif // #if !defined(__SPPROPERTYGRIDITEMNUMBER_H__)