1 // PropTree.h : header file 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 #if !defined(AFX_PROPT_H__386AA426_6FB7_4B4B_9563_C4CC045BB0C9__INCLUDED_) 20 #define AFX_PROPT_H__386AA426_6FB7_4B4B_9563_C4CC045BB0C9__INCLUDED_ 21 22 #if _MSC_VER > 1000 23 #pragma once 24 #endif // _MSC_VER > 1000 25 26 /*#ifdef _PROPTREE_EXPORT 27 #define PROPTREE_API __declspec(dllexport) 28 #else 29 #define PROPTREE_API __declspec(dllimport) 30 #endif 31 32 #ifndef _PROPTREE_DLL 33 #ifdef _UNICODE 34 #ifdef _DEBUG 35 #pragma comment(lib, "PropTreeDU") 36 #pragma message("Automatically linking with PropTreeDU.dll (Debug Unicode)") 37 #else 38 #pragma comment(lib, "PropTreeU") 39 #pragma message("Automatically linking with PropTreeU.dll (Release Unicode)") 40 #endif 41 #else 42 #ifdef _DEBUG 43 #pragma comment(lib, "PropTreeD") 44 #pragma message("Automatically linking with PropTreeD.dll (Debug)") 45 #else 46 #pragma comment(lib, "PropTree") 47 #pragma message("Automatically linking with PropTree.dll (Release)") 48 #endif 49 #endif // _UNICODE 50 #endif // _PROPTREE_DLL 51 */ 52 53 #define PROPTREE_API 54 55 #include "PropTreeList.h" 56 #include "PropTreeInfo.h" 57 58 #include "PropTreeItem.h" 59 #include "PropTreeItemStatic.h" 60 #include "PropTreeItemEdit.h" 61 #include "PropTreeItemCombo.h" 62 #include "PropTreeItemColor.h" 63 #include "PropTreeItemCheck.h" 64 #include "PropTreeItemButton.h" 65 #include "PropTreeItemEditButton.h" 66 #include "PropTreeItemFileEdit.h" 67 68 class CPropTree; 69 70 typedef BOOL (CALLBACK* ENUMPROPITEMPROC)(CPropTree*, CPropTreeItem*, LPARAM); 71 72 void InitPropTree(HINSTANCE hInstance); 73 74 // CPropTree window styles 75 #define PTS_NOTIFY 0x00000001 76 77 // CPropTree HitTest return codes 78 #define HTPROPFIRST 50 79 80 #define HTLABEL (HTPROPFIRST + 0) 81 #define HTCOLUMN (HTPROPFIRST + 1) 82 #define HTEXPAND (HTPROPFIRST + 2) 83 #define HTATTRIBUTE (HTPROPFIRST + 3) 84 #define HTCHECKBOX (HTPROPFIRST + 4) 85 #define HTBUTTON (HTPROPFIRST + 5) 86 87 // CPropTree WM_NOTIFY notification structure 88 typedef struct _NMPROPTREE 89 { 90 NMHDR hdr; 91 CPropTreeItem* pItem; 92 } NMPROPTREE, *PNMPROPTREE, FAR *LPNMPROPTREE; 93 94 // CPropTree specific Notification Codes 95 #define PTN_FIRST (0U-1100U) 96 97 #define PTN_INSERTITEM (PTN_FIRST-1) 98 #define PTN_DELETEITEM (PTN_FIRST-2) 99 #define PTN_DELETEALLITEMS (PTN_FIRST-3) 100 #define PTN_ITEMCHANGED (PTN_FIRST-5) 101 #define PTN_ITEMBUTTONCLICK (PTN_FIRST-6) 102 #define PTN_SELCHANGE (PTN_FIRST-7) 103 #define PTN_ITEMEXPANDING (PTN_FIRST-8) 104 #define PTN_COLUMNCLICK (PTN_FIRST-9) 105 #define PTN_PROPCLICK (PTN_FIRST-10) 106 #define PTN_CHECKCLICK (PTN_FIRST-12) 107 108 ///////////////////////////////////////////////////////////////////////////// 109 // CPropTree window 110 111 class PROPTREE_API CPropTree : public CWnd 112 { 113 // Construction 114 public: 115 CPropTree(); 116 virtual ~CPropTree(); 117 118 BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID); 119 120 // Attributes/Operations 121 public: 122 static CFont* GetNormalFont(); 123 static CFont* GetBoldFont(); 124 125 // Returns the root item of the tree 126 CPropTreeItem* GetRootItem(); 127 128 // Returns the focused item or NULL for none 129 CPropTreeItem* GetFocusedItem(); 130 131 // Enumerates an item and all its child items 132 BOOL EnumItems(CPropTreeItem* pItem, ENUMPROPITEMPROC proc, LPARAM lParam = 0L); 133 134 // Insert a created CPropTreeItem into the control 135 CPropTreeItem* InsertItem(CPropTreeItem* pItem, CPropTreeItem* pParent = NULL); 136 137 // Delete an item and ALL its children 138 void DeleteItem(CPropTreeItem* pItem); 139 140 // Delete all items from the tree 141 void DeleteAllItems(); 142 143 // Return the splitter position 144 LONG GetColumn(); 145 146 // Set the splitter position 147 void SetColumn(LONG nColumn); 148 149 // Sets the focused item 150 void SetFocusedItem(CPropTreeItem* pItem); 151 152 // Show or hide the info text 153 void ShowInfoText(BOOL bShow = TRUE); 154 155 // Returns TRUE if the item is visible (its parent is expanded) 156 BOOL IsItemVisible(CPropTreeItem* pItem); 157 158 // Ensures that an item is visible 159 void EnsureVisible(CPropTreeItem* pItem); 160 161 // do a hit test on the control (returns a HTxxxx code) 162 LONG HitTest(const POINT& pt); 163 164 // find an item by a location 165 CPropTreeItem* FindItem(const POINT& pt); 166 167 // find an item by item id 168 CPropTreeItem* FindItem(UINT nCtrlID); 169 170 protected: 171 // Actual tree control 172 CPropTreeList m_List; 173 174 // Descriptive control 175 CPropTreeInfo m_Info; 176 177 // TRUE to show info control 178 BOOL m_bShowInfo; 179 180 // Height of the info control 181 LONG m_nInfoHeight; 182 183 // Root level tree item 184 CPropTreeItem m_Root; 185 186 // Linked list of visible items 187 CPropTreeItem* m_pVisbleList; 188 189 // Pointer to the focused item (selected) 190 CPropTreeItem* m_pFocus; 191 192 // PropTree scroll position. x = splitter position, y = vscroll position 193 CPoint m_Origin; 194 195 // auto generated last created ID 196 UINT m_nLastUID; 197 198 // Number of CPropTree controls in the current application 199 static UINT s_nInstanceCount; 200 201 static CFont* s_pNormalFont; 202 static CFont* s_pBoldFont; 203 204 BOOL m_bDisableInput; 205 206 // Used for enumeration 207 static CPropTreeItem* s_pFound; 208 209 public: 210 // 211 // functions used by CPropTreeItem (you normally dont need to call these directly) 212 // 213 214 void AddToVisibleList(CPropTreeItem* pItem); 215 void ClearVisibleList(); 216 217 void SetOriginOffset(LONG nOffset); 218 void UpdatedItems(); 219 void UpdateMoveAllItems(); 220 void RefreshItems(CPropTreeItem* pItem = NULL); 221 222 // enable or disable tree input 223 void DisableInput(BOOL bDisable = TRUE); 224 BOOL IsDisableInput(); 225 226 BOOL IsSingleSelection(); 227 228 CPropTreeItem* GetVisibleList(); 229 CWnd* GetCtrlParent(); 230 231 const POINT& GetOrigin(); 232 233 void SelectItems(CPropTreeItem* pItem, BOOL bSelect = TRUE); 234 235 // Focus on the first visible item 236 CPropTreeItem *FocusFirst(); 237 238 // Focus on the last visible item 239 CPropTreeItem *FocusLast(); 240 241 // Focus on the previous item 242 CPropTreeItem *FocusPrev(); 243 244 // Focus on the next item 245 CPropTreeItem *FocusNext(); 246 247 LRESULT SendNotify(UINT nNotifyCode, CPropTreeItem* pItem = NULL); 248 249 protected: 250 // Resize the child windows to fit the exact dimensions the CPropTree control 251 void ResizeChildWindows(int cx, int cy); 252 253 // Initialize global resources, brushes, fonts, etc. 254 void InitGlobalResources(); 255 256 // Free global resources, brushes, fonts, etc. 257 void FreeGlobalResources(); 258 259 // Recursive version of DeleteItem 260 void Delete(CPropTreeItem* pItem); 261 262 // Overrides 263 // ClassWizard generated virtual function overrides 264 //{{AFX_VIRTUAL(CPropTree) 265 //}}AFX_VIRTUAL 266 267 // Implementation 268 private: 269 static BOOL CALLBACK EnumFindItem(CPropTree* pProp, CPropTreeItem* pItem, LPARAM lParam); 270 static BOOL CALLBACK EnumSelectAll(CPropTree*, CPropTreeItem* pItem, LPARAM lParam); 271 static BOOL CALLBACK EnumMoveAll(CPropTree*, CPropTreeItem* pItem, LPARAM); 272 static BOOL CALLBACK EnumRefreshAll(CPropTree*, CPropTreeItem* pItem, LPARAM); 273 274 // Generated message map functions 275 protected: 276 //{{AFX_MSG(CPropTree) 277 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); 278 afx_msg void OnSize(UINT nType, int cx, int cy); 279 afx_msg void OnEnable(BOOL bEnable); 280 afx_msg void OnSysColorChange(); 281 //}}AFX_MSG 282 DECLARE_MESSAGE_MAP() 283 }; 284 285 ///////////////////////////////////////////////////////////////////////////// 286 287 //{{AFX_INSERT_LOCATION}} 288 // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 289 290 #endif // !defined(AFX_PROPT_H__386AA426_6FB7_4B4B_9563_C4CC045BB0C9__INCLUDED_) 291