1 // PropTreeItem.h
2 //
3 //  Copyright (C) 1998-2001 Scott Ramsay
4 //	sramsay@gonavi.com
5 //	http://www.gonavi.com
6 //
7 //  This material is provided "as is", with absolutely no warranty expressed
8 //  or implied. Any use is at your own risk.
9 //
10 //  Permission to use or copy this software for any purpose is hereby granted
11 //  without fee, provided the above notices are retained on all copies.
12 //  Permission to modify the code and to distribute modified code is granted,
13 //  provided the above notices are retained, and a notice that the code was
14 //  modified is included with the above copyright notice.
15 //
16 //	If you use this code, drop me an email.  I'd like to know if you find the code
17 //	useful.
18 
19 #ifndef _PROPTREEITEM_H
20 #define _PROPTREEITEM_H
21 
22 class CPropTree;
23 
24 class PROPTREE_API CPropTreeItem
25 {
26 // Construction
27 public:
28 	CPropTreeItem();
29 	virtual ~CPropTreeItem();
30 
31 // Attributes/Operations
32 public:
33 	// TreeItem states
34 	BOOL IsExpanded();
35 	BOOL IsSelected();
36 	BOOL IsChecked();
37 	BOOL IsReadOnly();
38 	BOOL IsActivated();
39 
40 	void Select(BOOL bSelect = TRUE);
41 	void Expand(BOOL bExpand = TRUE);
42 	void Check(BOOL bCheck = TRUE);
43 	void ReadOnly(BOOL bReadOnly = TRUE);
44 
45 	// Returns true if the item has a checkbox
46 	BOOL IsCheckBox();
47 
48 	// Pass in true, for the item to have a checkbox
49 	void HasCheckBox(BOOL bCheckbox = TRUE);
50 
51 	// Returns TRUE if the point is on the expand button
52 	BOOL HitExpand(const POINT& pt);
53 
54 	// Returns TRUE if the point is on the check box
55 	BOOL HitCheckBox(const POINT& pt);
56 
57 	// Overrideable - Returns TRUE if the point is on the button
HitButton(const POINT & pt)58 	virtual BOOL HitButton(const POINT& pt) { return false;}
59 
60 	// Returns TRUE if the item is on the root level. Root level items don't have attribute areas
61 	BOOL IsRootLevel();
62 
63 	// Returns the total height of the item and all its children
64 	LONG GetTotalHeight();
65 
66 	// Set the items label text
67 	void SetLabelText(LPCTSTR sLabel);
68 
69 	// Return the items label text
70 	LPCTSTR GetLabelText();
71 
72 	// Set the items info (description) text
73 	void SetInfoText(LPCTSTR sInfo);
74 
75 	// Get the items info (description) text
76 	LPCTSTR GetInfoText();
77 
78 	// Set the item's ID
79 	void SetCtrlID(UINT nCtrlID);
80 
81 	// Return the item's ID
82 	UINT GetCtrlID();
83 
84 	// Overrideable - draw the item's non attribute area
85 	virtual LONG DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y);
86 
87 	// call to mark attribute changes
88 	void CommitChanges();
89 
90 	// call to activate item attribute
91 	enum {
92 		ACTIVATE_TYPE_KEYBOARD,
93 		ACTIVATE_TYPE_MOUSE
94 	};
95 	void Activate(int activateType, CPoint point);
96 
97 	//
98 	// Overrideables
99 	//
100 
101 	// The attribute area needs drawing
102 	virtual void DrawAttribute(CDC* pDC, const RECT& rc);
103 
104 	// Return the height of the item
105 	virtual LONG GetHeight();
106 
107 	// Retrieve the item's attribute value
108 	virtual LPARAM GetItemValue();
109 
110 	// Set the item's attribute value
111 	virtual void SetItemValue(LPARAM lParam);
112 
113 	// Called when attribute area has changed size
114 	virtual void OnMove();
115 
116 	// Called when the item needs to refresh its data
117 	virtual void OnRefresh();
118 
119 	// Called when the item needs to commit its changes
120 	virtual void OnCommit();
121 
122 	// Called to activate the item
123 	virtual void OnActivate(int activateType, CPoint point);
124 
125 	//
126 	// Usually only CPropTree should calls these
127 	//
128 
129 	void SetPropOwner(CPropTree* pProp);
130 
131 	// Return the location of the PropItem
132 	const POINT& GetLocation();
133 
134 	// TreeItem link pointer access
135 	CPropTreeItem* GetParent();
136 	CPropTreeItem* GetSibling();
137 	CPropTreeItem* GetChild();
138 	CPropTreeItem* GetNextVisible();
139 
140 	void SetParent(CPropTreeItem* pParent);
141 	void SetSibling(CPropTreeItem* pSibling);
142 	void SetChild(CPropTreeItem* pChild);
143 	void SetNextVisible(CPropTreeItem* pVis);
144 
145 protected:
146 	// CPropTree class that this class belongs
147 	CPropTree*			m_pProp;
148 
149 	// TreeItem label name
150 	CString				m_sLabel;
151 
152 	// Descriptive info text
153 	CString				m_sInfo;
154 
155 	// TreeItem location
156 	CPoint				m_loc;
157 
158 	// TreeItem attribute size
159 	CRect				m_rc;
160 
161 	// user defined LPARAM value
162 	LPARAM				m_lParam;
163 
164 	// ID of control item (should be unique)
165 	UINT				m_nCtrlID;
166 
167 protected:
168 	enum TreeItemStates
169 	{
170 		TreeItemSelected =		0x00000001,
171 		TreeItemExpanded =		0x00000002,
172 		TreeItemCheckbox =		0x00000004,
173 		TreeItemChecked =		0x00000008,
174 		TreeItemActivated =		0x00000010,
175 		TreeItemReadOnly =		0x00000020,
176 	};
177 
178 	// TreeItem state
179 	DWORD				m_dwState;
180 
181 	// TRUE if item is activated
182 	BOOL				m_bActivated;
183 
184 	// TRUE if item has been commited once (activation)
185 	BOOL				m_bCommitOnce;
186 
187 	// Rectangle position of the expand button (if contains one)
188 	CRect				m_rcExpand;
189 
190 	// Rectangle position of the check box (if contains one)
191 	CRect				m_rcCheckbox;
192 
193 	// Rectangle position of the button (if contains one)
194 	CRect				m_rcButton;
195 
196 	// link pointers
197 	CPropTreeItem*		m_pParent;
198 	CPropTreeItem*		m_pSibling;
199 	CPropTreeItem*		m_pChild;
200 	CPropTreeItem*		m_pVis;
201 };
202 
203 #endif // _PROPTREEITEM_H
204