SPPropertyGridItemBool.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #if !defined(__SPPROPERTYGRIDITEMBOOL_H__)
  7. #define __SPPROPERTYGRIDITEMBOOL_H__
  8. #if _MSC_VER > 1000
  9. #pragma once
  10. #endif // _MSC_VER > 1000
  11. class CSPPropertyGridItemBool : public CSPPropertyGridItem
  12. {
  13. public:
  14. CSPPropertyGridItemBool( CString strCaption , BOOL bValue = FALSE , BOOL * pBindBool = NULL );
  15. CSPPropertyGridItemBool( UINT nID , BOOL bValue = FALSE , BOOL * pBindBool = NULL ); // <COMBINE CSPPropertyGridItemBool::CSPPropertyGridItemBool@CString@BOOL@BOOL*>
  16. virtual ~CSPPropertyGridItemBool();
  17. void SetBool( BOOL bValue );
  18. BOOL GetBool();
  19. void BindToBool( BOOL * pBindBool );
  20. BOOL SetTrueFalseText( CString strTrueText , CString strFalseText );
  21. protected:
  22. void SetValue( CString strValue );
  23. BOOL SetValueText( CString & strValueText , CString strNewText );
  24. virtual void OnBeforeInsert();
  25. private:
  26. void _Init( BOOL bValue );
  27. protected:
  28. BOOL m_bValue; // Value of the item.
  29. BOOL * m_pBindBool; // Binded value. This is a pointer to the variable bound to this item.
  30. CString m_strTrueText; // Text of the TRUE label.
  31. CString m_strFalseText; // Text of the FALSE label.
  32. private:
  33. DECLARE_DYNAMIC( CSPPropertyGridItemBool )
  34. };
  35. //===========================================================================
  36. // Summary:
  37. // CSPPropertyGridItemEnum is a CSPPropertyGridItem derived class.
  38. // It is used to create an Enum value item in a Property Grid control.
  39. // Remarks:
  40. // A Enum item is used to display a list of constraints. This is
  41. // very similar to a normal constraint list. The difference is that
  42. // an Enum constraint list will return the Value of the constraint when
  43. // selected, where a normal constraint wold return the text of the
  44. // constraint.
  45. //
  46. // Example:
  47. // This code illustrates how to add an item of type Enum to your grid.
  48. // <code>
  49. // //Adds a category to the grid called "Software"
  50. // CSPPropertyGridItem* pStandard = m_wndPropertyGrid.AddCategory(_T("Software"));
  51. //
  52. // //Adds a CSPPropertyGridItemFlags item with a caption of "Current OS" and an initial value of 2
  53. // //This will cause the constraint with a value of 2 to be selected
  54. // CSPPropertyGridItemEnum* pItem = (CSPPropertyGridItemEnum*)(pStandard->AddChildItem(new CSPPropertyGridItemEnum(_T("Current OS"), 2)));
  55. //
  56. // //Adds some constraints along with a value
  57. // pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 1);
  58. // pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 2);
  59. // pItem->GetConstraints()->AddConstraint(_T("Windows XP"), 3);
  60. //
  61. // //GetEnum will return the Data value of the constraint selected
  62. // TRACE(_T("Enum Item Value= %d\n"), pItem->GetEnum());
  63. //
  64. // //GetValue will return the String of the constraint selected
  65. // TRACE(_T("Enum Item String= %s\n"), pItem->GetValue());
  66. // </code>
  67. //
  68. // See Also: CSPPropertyGridItemEnum::SetEnum, CSPPropertyGridItemEnum::GetEnum, CSPPropertyGridItem::GetValue
  69. //===========================================================================
  70. class CSPPropertyGridItemEnum : public CSPPropertyGridItem
  71. {
  72. public:
  73. CSPPropertyGridItemEnum( CString strCaption , int nValue = 0 , int * pBindEnum = NULL );
  74. CSPPropertyGridItemEnum( UINT nID , int nValue = 0 , int * pBindEnum = NULL ); // <COMBINE CSPPropertyGridItemEnum::CSPPropertyGridItemEnum@CString@int@int*>
  75. virtual ~CSPPropertyGridItemEnum();
  76. void SetEnum( int nValue );
  77. void SetEnum( CSPPropertyGridItemConstraint * pContraint ); // <COMBINE CSPPropertyGridItemEnum::SetEnum@int>
  78. int GetEnum();
  79. void BindToEnum( int * pBindEnum );
  80. protected:
  81. void SetValue( CString strValue );
  82. virtual void OnBeforeInsert();
  83. virtual void OnConstraintsChanged();
  84. private:
  85. void _Init( int nValue );
  86. protected:
  87. int m_nValue; // Value of the item. This will contain the value of the selected constraint, not the text
  88. int * m_pBindEnum; // Binded value. This is a pointer to the variable bound to this item.
  89. private:
  90. DECLARE_DYNAMIC( CSPPropertyGridItemEnum )
  91. };
  92. //===========================================================================
  93. // Summary:
  94. // CSPPropertyGridItemFlags is a CSPPropertyGridItem derived class.
  95. // It is used to create a Flags value item in a Property Grid control.
  96. // Remarks:
  97. // A flag item is used to combine multiple boolean values into a
  98. // single item. When using a flag item, you must add constraints
  99. // to the flag item. Each constraint will have a value of TRUE or
  100. // FALSE. The flag item will have an expand button that when clicked
  101. // will display all boolean constraints for that item. The value of
  102. // the flag item will be the sum of all the boolean constraints with
  103. // a value of TRUE.
  104. //
  105. // NOTE: Constraint values must be in powers of 2 if you will have an
  106. // "All" constraint that indicates that the value of all boolean
  107. // constraints is TRUE or FALSE.
  108. //
  109. // In the example below, the flag item's initial value will be 9, this
  110. // value is stored in CSPPropertyGridItemFlags::m_nValue and can be
  111. // set with SetFlags and retrieved with GetFlags. The string value will
  112. // be "[Windows 98; Windows 95]" and this value is stored in
  113. // CSPPropertyGridItem::m_strValue, which can be retrieved
  114. // with CSPPropertyGridItem::GetValue. You must use the SetFlags method
  115. // to change the flag items value by code. The string value is what is
  116. // displayed to the user.
  117. //
  118. // Example:
  119. // This sample illustrates how to add an item of type Flags to your grid.
  120. // <code>
  121. // //Adds a category to the grid called "Software"
  122. // CSPPropertyGridItem* pStandard = m_wndPropertyGrid.AddCategory(_T("Software"));
  123. //
  124. // //Adds a CSPPropertyGridItemFlags item with a caption of "Supported OS" and an initial value of 9
  125. // CSPPropertyGridItemFlags* pItem = (CSPPropertyGridItemFlags*)(pStandard->AddChildItem(new CSPPropertyGridItemFlags(_T("Supported OS"), 1 + 8)));
  126. //
  127. // //Adds a constraint that will set all items TRUE or FALSE, note the value of the constraint is the sum
  128. // //of all the other constraints. This item will also be updated when the values of the other constraints
  129. // //have changed.
  130. // pItem->GetConstraints()->AddConstraint(_T("All Windows"), 1 + 2 + 4 + 8 + 16 + 32);
  131. //
  132. // //Adds a constraint that can have a value of TRUE or FALSE
  133. // pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 1);
  134. // pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 2);
  135. // pItem->GetConstraints()->AddConstraint(_T("Windows XP"), 4);
  136. // pItem->GetConstraints()->AddConstraint(_T("Windows 95"), 8);
  137. // pItem->GetConstraints()->AddConstraint(_T("Windows NT"), 16);
  138. // pItem->GetConstraints()->AddConstraint(_T("Windows 2003"), 32);
  139. //
  140. // //This changes the value of the flag item to 21 and the string
  141. // //caption to [Windows 98; Windows XP; Windows NT]
  142. // pItem->SetFlags(21);
  143. //
  144. // //GetFlags will return the sum of all true constraints
  145. // TRACE(_T("Flags Item Value= %d\n"), pItem->GetFlags());
  146. //
  147. // //GetValue will return a string containing the text of all true constraints
  148. // TRACE(_T("Flags Item String= %s\n"), pItem->GetValue());
  149. // </code>
  150. //
  151. // See Also: CSPPropertyGridItemFlags::SetFlags, CSPPropertyGridItemFlags::GetFlags, CSPPropertyGridItem::GetValue
  152. //===========================================================================
  153. class CSPPropertyGridItemFlags : public CSPPropertyGridItem
  154. {
  155. public:
  156. CSPPropertyGridItemFlags( CString strCaption , int nValue = 0 , int * pBindFlags = NULL );
  157. CSPPropertyGridItemFlags( UINT nID , int nValue = 0 , int * pBindFlags = NULL ); // <COMBINE CSPPropertyGridItemFlags::CSPPropertyGridItemFlags@CString@int@int*>
  158. virtual ~CSPPropertyGridItemFlags();
  159. void SetFlags( int nValue );
  160. int GetFlags();
  161. void BindToFlags( int * pBindFlags );
  162. protected:
  163. void SetValue( CString strValue );
  164. virtual void OnBeforeInsert();
  165. virtual void OnConstraintsChanged();
  166. virtual CString GetFlagsString();
  167. void UpdateChilds();
  168. class CSPPropertyGridItemFlag;
  169. private:
  170. void _Init( int nValue );
  171. protected:
  172. int m_nValue; // Value of the item. This is the sum of the constraint values that have a value of TRUE.
  173. int * m_pBindFlags; // Binded value. This is a pointer to the variable bound to this item.
  174. private:
  175. DECLARE_DYNAMIC( CSPPropertyGridItemFlags )
  176. friend class CSPPropertyGridItemFlag;
  177. };
  178. //////////////////////////////////////////////////////////////////////
  179. AFX_INLINE BOOL CSPPropertyGridItemBool::GetBool()
  180. {
  181. return m_bValue;
  182. }
  183. AFX_INLINE BOOL CSPPropertyGridItemEnum::GetEnum()
  184. {
  185. return m_nValue;
  186. }
  187. AFX_INLINE BOOL CSPPropertyGridItemFlags::GetFlags()
  188. {
  189. return m_nValue;
  190. }
  191. #endif // #if !defined(__SPPROPERTYGRIDITEMBOOL_H__)