// PropTreeItem.h // // Copyright (C) 1998-2001 Scott Ramsay // sramsay@gonavi.com // http://www.gonavi.com // // This material is provided "as is", with absolutely no warranty expressed // or implied. Any use is at your own risk. // // Permission to use or copy this software for any purpose is hereby granted // without fee, provided the above notices are retained on all copies. // Permission to modify the code and to distribute modified code is granted, // provided the above notices are retained, and a notice that the code was // modified is included with the above copyright notice. // // If you use this code, drop me an email. I'd like to know if you find the code // useful. #ifndef __CPropITEM_H__ #define __CPropITEM_H__ #ifdef GRID_EXPORT #define THVAC_UIAPI __declspec( dllexport ) #else #define THVAC_UIAPI __declspec( dllimport ) #endif // 定义消息,在所在对话框中这样接受: // .h afx_msg void ButtonClick(WPARAM iParam1, LPARAM iParam2); // .cpp ON_MESSAGE(WM_EBTNCLICK, ButtonClick) #define WM_EBTNCLICK 1980 #define WM_EBKILLFOCUS 1983 #define IDC_BUTTON 1981 #define BUTTON_WIDTH 16 // 按钮宽度 #define IDC_SPINCTRL 2008 #define SPINCTRL_WIDTH 15 // Sipn class CPropCtrl; enum eItemType{ ITEMTYPE_NULL = 0, ITEMTYPE_EDIT = 1, ITEMTYPE_COMBOBOX = 2, ITEMTYPE_STATIC = 3, ITEMTYPE_COLOR = 4 }; class THVAC_UIAPI CPropItem { public: CPropItem(); virtual ~CPropItem(); public: // TreeItem states BOOL IsExpanded(); BOOL IsSelected(); BOOL IsChecked(); BOOL IsReadOnly(); BOOL IsActivated(); BOOL IsHide(); void HasSpinCtrl(BOOL bHas = TRUE); void CreateSpinCtrl(CWnd* pWnd); void HasButton(BOOL bHas = TRUE); void CreateButton(CWnd* pWnd); void ShowButton(BOOL bShow = TRUE); void ShowSpinCtrl(BOOL bShow = TRUE); void CreateEdit( CWnd* pWnd ); void Select(BOOL bSelect = TRUE); void Expand(BOOL bExpand = TRUE); void Check(BOOL bCheck = TRUE); void ReadOnly(BOOL bReadOnly = TRUE); void Hide(BOOL bHide = TRUE); // Returns true if the item has a checkbox BOOL IsCheckBox(); // Pass in true, for the item to have a checkbox void HasCheckBox(BOOL bCheckbox = TRUE); // Returns TRUE if the point is on the expand button BOOL HitExpand(const POINT& pt); // Returns TRUE if the point is on the check box BOOL HitCheckBox(const POINT& pt); // Returns TRUE if the point is on the Button BOOL HitButton(const POINT& pt); // Returns TRUE if the item is on the root level. Root level items don't have attribute areas BOOL IsRootLevel(); // Returns the total height of the item and all its children LONG GetTotalHeight(); // Set the items label text void SetLabelText(LPCTSTR sLabel); // Return the items label text LPCTSTR GetLabelText(); // Set the items info (description) text void SetInfoText(LPCTSTR sInfo); // Get the items info (description) text LPCTSTR GetInfoText(); // Set the item's ID void SetCtrlID(UINT nCtrlID); // Return the item's ID UINT GetCtrlID(); // draw the item's non attribute area LONG DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y); // call to mark attribute changes void CommitChanges(); // call to activate item attribute void Activate(); // // Overrideables // // The attribute area needs drawing virtual void DrawAttribute(CDC* pDC, const RECT& rc); // Return the height of the item virtual LONG GetHeight(); // Retrieve the item's attribute value virtual LPARAM GetItemValue(); // Set the item's attribute value virtual void SetItemValue(LPARAM lParam); // Called when attribute area has changed size virtual void OnMove(); // Called when the item needs to refresh its data virtual void OnRefresh(); // Called when the item needs to commit its changes virtual void OnCommit(); // Called to activate the item virtual void OnActivate(); // // Usually only CPropCtrl should calls these // void SetPropOwner(CPropCtrl* pProp); CPropCtrl* GetPropOwner(); // Return the location of the PropItem const POINT& GetLocation(); // TreeItem link pointer access CPropItem* GetParent(); CPropItem* GetSibling(); CPropItem* GetChild(); CPropItem* GetNextVisible(); void SetParent(CPropItem* pParent); void SetSibling(CPropItem* pSibling); void SetChild(CPropItem* pChild); void SetNextVisible(CPropItem* pVis); public: // TreeItem attribute size CRect m_rc; int m_nItemType; protected: // CPropCtrl class that this class belongs CPropCtrl* m_pProp; // TreeItem label name CString m_sLabel; // Descriptive info text CString m_sInfo; // TreeItem location CPoint m_loc; // user defined LPARAM value LPARAM m_lParam; // ID of control item (should be unique) UINT m_nCtrlID; // hide the item BOOL m_bHide; // has a button BOOL m_bHasBt; // has a SpinCtrl BOOL m_bHasSpinCtrl; private: enum TreeItemStates { TreeItemSelected = 0x00000001, TreeItemExpanded = 0x00000002, TreeItemCheckbox = 0x00000004, TreeItemChecked = 0x00000008, TreeItemActivated = 0x00000010, TreeItemReadOnly = 0x00000020, }; // TreeItem state DWORD m_dwState; // TRUE if item is activated BOOL m_bActivated; // TRUE if item has been commited once (activation) BOOL m_bCommitOnce; // Rectangle position of the expand button (if contains one) CRect m_rcExpand; // Rectangle position of the check box (if contains one) CRect m_rcCheckbox; // Rectangle position of the Button box (if Has) CRect m_rcButton; // Rectangle position of the SpinCtrl box (if Has) CRect m_rcSpinCtrl; // link pointers CPropItem* m_pParent; CPropItem* m_pSibling; CPropItem* m_pChild; CPropItem* m_pVis; }; #endif // __CPropITEM_H__