SPPropertyGridView.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #if !defined(__SPPROPERTYGRIDVIEW_H__)
  7. #define __SPPROPERTYGRIDVIEW_H__
  8. #if _MSC_VER > 1000
  9. #pragma once
  10. #endif // _MSC_VER > 1000
  11. #include "SPPropertyGridPaintManager.h"
  12. #include "SPDrawHelpers.h"
  13. class CSPPropertyGridView;
  14. class CSPPropertyGridPaintManager;
  15. class CSPPropertyGrid;
  16. //===========================================================================
  17. // Summary:
  18. // CSPPropertyGridToolTip is a CWnd derived class.
  19. // It is an internal class used by Property Grid control
  20. //===========================================================================
  21. class CSPPropertyGridToolTip : public CWnd
  22. {
  23. public:
  24. //-----------------------------------------------------------------------
  25. // Summary:
  26. // Activate Tooltip control.
  27. // Parameters:
  28. // bActive - TRUE to activate.
  29. //-----------------------------------------------------------------------
  30. void Activate( BOOL bActive );
  31. //-----------------------------------------------------------------------
  32. // Summary:
  33. // Creates Tooltip control.
  34. // Parameters:
  35. // pParentWnd - Points to a CSPPropertyGridView object.
  36. //-----------------------------------------------------------------------
  37. void Create( CSPPropertyGridView * pParentWnd );
  38. protected:
  39. CSPPropertyGridView * m_pGrid; // Parent window.
  40. protected:
  41. //{{AFX_CODEJOCK_PRIVATE
  42. DECLARE_MESSAGE_MAP()
  43. //{{AFX_MSG(CSPPropertyGridView)
  44. afx_msg BOOL OnEraseBkgnd(CDC*);
  45. afx_msg void OnPaint();
  46. afx_msg LRESULT OnNcHitTest(CPoint point);
  47. //}}AFX_MSG
  48. //}}AFX_CODEJOCK_PRIVATE
  49. private:
  50. BOOL Create( LPCTSTR lpszClassName , LPCTSTR lpszWindowName , DWORD dwStyle , const RECT & rect , CWnd * pParentWnd , UINT nID , CCreateContext * pContext = NULL );
  51. };
  52. AFX_INLINE BOOL CSPPropertyGridToolTip::Create( LPCTSTR lpszClassName , LPCTSTR lpszWindowName , DWORD dwStyle , const RECT & rect , CWnd * pParentWnd , UINT nID , CCreateContext * pContext )
  53. {
  54. return CWnd::Create( lpszClassName,lpszWindowName,dwStyle,rect,pParentWnd,nID,pContext );
  55. }
  56. //===========================================================================
  57. // Summary:
  58. // CSPPropertyGridView is a CListBox derived class.
  59. // It is an internal class used by Property Grid control
  60. //===========================================================================
  61. class CSPPropertyGridView : public CListBox
  62. {
  63. DECLARE_DYNAMIC( CSPPropertyGridView )
  64. public:
  65. //-----------------------------------------------------------------------
  66. // Summary:
  67. // Constructs a CSPPropertyGridView object
  68. //-----------------------------------------------------------------------
  69. CSPPropertyGridView();
  70. //-----------------------------------------------------------------------
  71. // Summary:
  72. // Destroys a CSPPropertyGridView object, handles cleanup and
  73. // deallocation.
  74. //-----------------------------------------------------------------------
  75. virtual ~CSPPropertyGridView();
  76. //-----------------------------------------------------------------------
  77. // Summary:
  78. // Call this method to get the position of the divider.
  79. // Returns:
  80. // Position of the divider
  81. //-----------------------------------------------------------------------
  82. int GetDividerPos();
  83. //-----------------------------------------------------------------------
  84. // Summary:
  85. // This method determines where a point lies in a specified item.
  86. // Parameters:
  87. // point - Specifies the point to be tested.
  88. // Returns:
  89. // A pointer to a CSPPropertyGridItem object
  90. //-----------------------------------------------------------------------
  91. CSPPropertyGridItem * ItemFromPoint( CPoint point );
  92. //-----------------------------------------------------------------------
  93. // Summary:
  94. // Call this method to refresh items in the list.
  95. //-----------------------------------------------------------------------
  96. void Refresh();
  97. //-----------------------------------------------------------------------
  98. // Summary:
  99. // Call this method to remove all items in the list.
  100. //-----------------------------------------------------------------------
  101. void ResetContent();
  102. //-----------------------------------------------------------------------
  103. // Summary:
  104. // This method retrieves an item with the specified index.
  105. // Parameters:
  106. // nIndex - Specifies the zero-based index of the item to retrieve.
  107. // Returns:
  108. // A pointer to a CSPPropertyGridItem object
  109. //-----------------------------------------------------------------------
  110. CSPPropertyGridItem * GetItem( int nIndex );
  111. //-----------------------------------------------------------------------
  112. // Summary:
  113. // Call this member function to add a new category to a Property
  114. // Grid Control.
  115. // Parameters:
  116. // strCaption - Name of the category to add.
  117. // pCategory - Points to a CSPPropertyGridItem object.
  118. // Returns:
  119. // A pointer to a CSPPropertyGridItem object.
  120. //-----------------------------------------------------------------------
  121. CSPPropertyGridItem * AddCategory( CString strCaption , CSPPropertyGridItem * pCategory = NULL );
  122. //-----------------------------------------------------------------------
  123. // Summary:
  124. // Call this member function to insert a new category to the Property Grid control.
  125. // Parameters:
  126. // strCaption - Name of the category to add.
  127. // nIndex - Index of category to be inserted
  128. // pCategory - Points to a CSPPropertyGridItem object.
  129. // Returns:
  130. // The pointer to the item object of the newly inserted category.
  131. //-----------------------------------------------------------------------
  132. CSPPropertyGridItem * InsertCategory( int nIndex , CString strCaption , CSPPropertyGridItem * pCategory = NULL );
  133. private:
  134. CSPPropertyGridItem * GetSelectedItem();
  135. void SetPropertySort( SPPropertyGridSortOrder sort , BOOL bRrefresh = FALSE );
  136. int InsertItem( CSPPropertyGridItem * pItem , int nIndex );
  137. int _DoExpand( CSPPropertyGridItem * pItem , int nIndex );
  138. void _DoCollapse( CSPPropertyGridItem * pItem );
  139. void _RefreshIndexes();
  140. void SwitchExpandState( int nItem );
  141. int HitTest( CPoint point );
  142. void ShowToolTip( CPoint pt );
  143. void _ShowToolTip( CRect rcBound , CRect rcText );
  144. CSize _GetTextExtent( CString str );
  145. void RelayToolTipEvent( UINT message );
  146. public:
  147. CFont m_fontNormal; // Normal font.
  148. CFont m_fontBold; // Bold font.
  149. CSPPaintManagerColor m_clrLine; // Line color.
  150. CSPPaintManagerColor m_clrFore; // Color of the item's text.
  151. CSPPaintManagerColor m_clrCategoryFore; // Color of the category text.
  152. CSPPaintManagerColor m_clrBack; // Background color.
  153. CSPPaintManagerColor m_clrReadOnlyFore; // Color of read-only text.
  154. CSPPropertyGrid * m_pGrid; // Parent CSPPropertyGrid class.
  155. protected:
  156. BOOL m_bTracking; // TRUE if grid in tracking mode.
  157. CRect m_rcToolTip; // Position of the Tooltip.
  158. double m_dDivider; // Divider position.
  159. HCURSOR m_hCursor; // Handle of the cursor.
  160. CString m_strTipText; // Tooltip text.
  161. SPPropertyGridSortOrder m_properetySort; // Current sort order.
  162. CSPPropertyGridItem * m_pSelected; // Current selected item.
  163. CSPPropertyGridItems * m_pCategories; // Collection of the categories.
  164. CSPPropertyGridToolTip m_wndTip; // Tooltip control.
  165. CSPPropertyGridInplaceEdit m_wndEdit; // In-place edit control.
  166. CSPPropertyGridInplaceButton m_wndButton; // In-place button control.
  167. CSPPropertyGridInplaceList m_wndListBox; // In-place list control.
  168. int m_nLockUpdate; // TRUE to lock update.
  169. protected:
  170. //{{AFX_CODEJOCK_PRIVATE
  171. //{{AFX_VIRTUAL(CSPPropertyGridView)
  172. virtual void DrawItem(LPDRAWITEMSTRUCT);
  173. virtual void MeasureItem(LPMEASUREITEMSTRUCT);
  174. virtual int CompareItem(LPCOMPAREITEMSTRUCT) { return 0;}
  175. virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
  176. //}}AFX_VIRTUAL
  177. //{{AFX_MSG(CSPPropertyGridView)
  178. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  179. afx_msg void OnPaint();
  180. afx_msg void OnNcPaint();
  181. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  182. afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
  183. afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  184. afx_msg void OnSelectionChanged();
  185. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  186. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  187. afx_msg void OnCaptureChanged(CWnd *pWnd);
  188. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  189. afx_msg void OnSize(UINT nType, int cx, int cy);
  190. afx_msg void OnChar(UINT nChar, UINT nRepCntr, UINT nFlags);
  191. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  192. afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
  193. afx_msg UINT OnGetDlgCode();
  194. afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  195. afx_msg void OnSysKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
  196. afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  197. afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
  198. afx_msg void OnSetFocus(CWnd* pOldWnd);
  199. afx_msg void OnKillFocus (CWnd* pNewWnd);
  200. //}}AFX_MSG
  201. //}}AFX_CODEJOCK_PRIVATE
  202. private:
  203. DECLARE_MESSAGE_MAP()
  204. friend class CSPPropertyGridItem;
  205. friend class CSPPropertyGridItems;
  206. friend class CSPPropertyGrid;
  207. friend class CSPPropertyGridInplaceEdit;
  208. friend class CPropertyGridCtrl;
  209. friend class CSPPropertyGridToolTip;
  210. };
  211. #endif // #if !defined(__SPPROPERTYGRIDVIEW_H__)