SPPropertyGridItemColor.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #if !defined(__SPPROPERTYGRIDITEMCOLOR_H__)
  7. #define __SPPROPERTYGRIDITEMCOLOR_H__
  8. #if _MSC_VER > 1000
  9. #pragma once
  10. #endif // _MSC_VER > 1000
  11. //===========================================================================
  12. // Summary:
  13. // CSPPropertyGridItemColor is a CSPPropertyGridItem derived class.
  14. // It is used to create an RGB value item in a Property Grid control.
  15. //===========================================================================
  16. class CSPPropertyGridItemColor : public CSPPropertyGridItem
  17. {
  18. public:
  19. //-----------------------------------------------------------------------
  20. // Summary:
  21. // Constructs a CSPPropertyGridItemColor object.
  22. // Parameters:
  23. // strCaption - Caption of the item.
  24. // nID - Identifier of the item.
  25. // clr - Initial color value for this item.
  26. // pBindColor - If not NULL, then the value of this item
  27. // is bound the value of this variable.
  28. // Remarks:
  29. // Class CSPPropertyGridItemColor 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. // BindToColor 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: BindToColor
  54. //-----------------------------------------------------------------------
  55. CSPPropertyGridItemColor( CString strCaption , COLORREF clr = 0 , COLORREF * pBindColor = NULL );
  56. CSPPropertyGridItemColor( UINT nID , COLORREF clr = 0 , COLORREF * pBindColor = NULL ); // <COMBINE CSPPropertyGridItemColor::CSPPropertyGridItemColor@CString@COLORREF@COLORREF*>
  57. //-----------------------------------------------------------------------
  58. // Summary:
  59. // Destroys a CSPPropertyGridItemColor object
  60. //-----------------------------------------------------------------------
  61. virtual ~CSPPropertyGridItemColor();
  62. public:
  63. //-----------------------------------------------------------------------
  64. // Summary:
  65. // Call this method to change the item's value.
  66. // Parameters:
  67. // clr - The new RGB value of the item.
  68. //-----------------------------------------------------------------------
  69. void SetColor( COLORREF clr );
  70. //-----------------------------------------------------------------------
  71. // Summary:
  72. // Call this method to get the RGB value of the item.
  73. // Returns:
  74. // An RGB value.
  75. //-----------------------------------------------------------------------
  76. COLORREF GetColor();
  77. //-----------------------------------------------------------------------
  78. // Summary:
  79. // The StringToRGB function converts a string to a COLORREF.
  80. // Parameters:
  81. // str - String that is converted to a COLORREF.
  82. // Format of string is RRR;GGG;BBB
  83. // Returns:
  84. // An COLORREF RGB value.
  85. //-----------------------------------------------------------------------
  86. static COLORREF AFX_CDECL StringToRGB( CString str );
  87. //-----------------------------------------------------------------------
  88. // Summary:
  89. // The RGBToString function converts a COLORREF to a string.
  90. // Parameters:
  91. // clr - COLORREF that is converted to a string.
  92. // Returns:
  93. // Returns a string in the format RRR;GGG;BBB
  94. //-----------------------------------------------------------------------
  95. static CString AFX_CDECL RGBToString( COLORREF clr );
  96. //-----------------------------------------------------------------------
  97. // Summary:
  98. // Call this method to bind an item to a COLORREF object.
  99. // Parameters:
  100. // pBindColor - COLORREF object to bind to item.
  101. // Remarks:
  102. // Variables can be bound to an item in two ways, the first is
  103. // to pass in a variable at the time of creation, the second allows
  104. // variables to be bound to an item after creation with the
  105. // BindToColor member.
  106. //
  107. // Bound variables store the values of the property grid items
  108. // and can be accessed without using the property grid methods
  109. // and properties. Bound variables allow the property grid to
  110. // store data in variables. When the value of a PropertyGridItem
  111. // is changed, the value of the bound variable will be changed to
  112. // the PropertyGridItem value. The advantage of binding is that
  113. // the variable can be used and manipulated without using
  114. // PropertyGridItem methods and properties.
  115. //
  116. // NOTE: If the value of the variable is changed without using
  117. // the PropertyGrid, the PropertyGridItem value will not be
  118. // updated until you call CSPPropertyGrid::Refresh.
  119. //-----------------------------------------------------------------------
  120. void BindToColor( COLORREF * pBindColor );
  121. protected:
  122. //-----------------------------------------------------------------------
  123. // Summary:
  124. // This method is called when an item is drawn. Override this function if
  125. // needed.
  126. // Parameters:
  127. // dc - Reference to the device context to be used for rendering an image
  128. // of the item.
  129. // rcValue - Bounding rectangle of the item.
  130. // Returns:
  131. // TRUE if the item is self-drawn.
  132. //-----------------------------------------------------------------------
  133. virtual BOOL OnDrawItemValue( CDC & dc , CRect rcValue );
  134. //-----------------------------------------------------------------------
  135. // Summary:
  136. // Retrieves the bounding rectangle of the item value's text.
  137. // Override this member function to change it.
  138. // Returns:
  139. // A CRect object that represents the bounding rectangle of the
  140. // item value's text.
  141. //-----------------------------------------------------------------------
  142. virtual CRect GetValueRect();
  143. //-----------------------------------------------------------------------
  144. // Summary:
  145. // Call this method to change an item's value.
  146. // Override this method to add new functionality.
  147. // You should call the base class version of this function from your
  148. // override.
  149. // Parameters:
  150. // strValue - New value of the item.
  151. //-----------------------------------------------------------------------
  152. virtual void SetValue( CString strValue );
  153. //-----------------------------------------------------------------------
  154. // Summary:
  155. // This method is called when the user presses the in-place button.
  156. // Override the method to show an item-specific dialog.
  157. // Remarks:
  158. // The in-place button is the button that the user presses to
  159. // display the color picker dialog.
  160. //-----------------------------------------------------------------------
  161. virtual void OnInplaceButtonDown();
  162. //-------------------------------------------------------------------------
  163. // Summary:
  164. // This member is called before the item becomes visible in the
  165. // property grid.
  166. // Remarks:
  167. // Before the item is inserted, it is first check to see if it
  168. // is bound to a variable, if it is, then the value of the item
  169. // is updated with the value stored in the bound variable.
  170. //
  171. // OnBeforeInsert is called when an item is inserted,
  172. // when a category is inserted, when a category or item is
  173. // expanded, and when the sort property has changed.
  174. //-------------------------------------------------------------------------
  175. void OnBeforeInsert();
  176. protected:
  177. COLORREF m_clrValue; // Color value of the item.
  178. COLORREF * m_pBindColor; // Pointer to variable bound to this item, this is the color of the bound item.
  179. private:
  180. DECLARE_DYNAMIC( CSPPropertyGridItemColor )
  181. };
  182. //////////////////////////////////////////////////////////////////////
  183. AFX_INLINE COLORREF CSPPropertyGridItemColor::GetColor()
  184. {
  185. return m_clrValue;
  186. }
  187. #endif //#if !defined(__SPPROPERTYGRIDITEMCOLOR_H__)