Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: treectrl.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // TreeCtrl.h : header file
  11. //
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAMCTreeView window
  14. #ifndef __TREECTRL_H__
  15. #define __TREECTRL_H__
  16. #include "fontlink.h"
  17. #include "contree.h" // for CConsoleTree
  18. #include "kbdnav.h" // for CKeyboardNavDelayTimer
  19. #include "dd.h"
  20. struct SDeleteNodeInfo
  21. {
  22. HTREEITEM htiToDelete;
  23. HTREEITEM htiSelected;
  24. BOOL fDeleteThis;
  25. };
  26. class CAMCTreeView;
  27. class CTreeFontLinker : public CFontLinker
  28. {
  29. public:
  30. CTreeFontLinker (CAMCTreeView* pTreeView) : m_pTreeView (pTreeView)
  31. { ASSERT (m_pTreeView != NULL); }
  32. protected:
  33. virtual std::wstring GetItemText (NMCUSTOMDRAW* pnmcd) const;
  34. private:
  35. CAMCTreeView* const m_pTreeView;
  36. };
  37. /*+-------------------------------------------------------------------------*
  38. * class CTreeViewMap
  39. *
  40. *
  41. * PURPOSE: Maintains a fast lookup for converting between tree items,
  42. * HNODES and HMTNODES.
  43. *
  44. *+-------------------------------------------------------------------------*/
  45. class CTreeViewMap : public CTreeViewObserver
  46. {
  47. // CTreeViewObserver methods
  48. public:
  49. virtual SC ScOnItemAdded (TVINSERTSTRUCT *pTVInsertStruct, HTREEITEM hti, HMTNODE hMTNode);
  50. virtual SC ScOnItemDeleted (HNODE hNode, HTREEITEM hti);
  51. // possible conversions
  52. // 1) HMTNODE to HNODE - slow. This class adds a fast lookup.
  53. // 2) HNODE to HTREEITEM - slow. This class adds a fast lookup.
  54. // 3) HMTNODE to HTREEITEM - slow. This class adds a fast lookup.
  55. // 4) HTREEITEM to HNODE - already fast. This class does not need to do this.
  56. // 5) HTREEITEM to HMTNODE - already fast. This class does not need to do this.
  57. // 6) HNODE to HMTNODE - already fast. This class does not need to do this.
  58. // Fast lookup methods
  59. SC ScGetHNodeFromHMTNode (HMTNODE hMTNode, /*out*/ HNODE* phNode); // fast conversion from hNode to hMTNode.
  60. SC ScGetHTreeItemFromHNode (HNODE hNode, /*out*/ HTREEITEM* phti); // fast conversion from HTREEITEM to HNODE
  61. SC ScGetHTreeItemFromHMTNode(HMTNODE hMTNode, /*out*/ HTREEITEM* phti); // fast conversion from HMTNode to HTREEITEM.
  62. // implementation
  63. private:
  64. // This structure holds two pieces to the puzzle together:
  65. typedef struct TreeViewMapInfo
  66. {
  67. HTREEITEM hti; // a tree item
  68. HMTNODE hMTNode; // the corresponding HMTNODE
  69. HNODE hNode; // the corresponding HNODE for the tree view control being observed.
  70. } *PTREEVIEWMAPINFO;
  71. typedef std::map<HNODE, PTREEVIEWMAPINFO> HNodeLookupMap;
  72. typedef std::map<HMTNODE, PTREEVIEWMAPINFO> HMTNodeLookupMap;
  73. HNodeLookupMap m_hNodeMap;
  74. HMTNodeLookupMap m_hMTNodeMap;
  75. };
  76. /*+-------------------------------------------------------------------------*
  77. * class CAMCTreeView
  78. *
  79. *
  80. * PURPOSE: The scope pane tree control. Responsible for adding and removing
  81. * items from the tree and also for sending events to
  82. * tree observers.
  83. *
  84. *+-------------------------------------------------------------------------*/
  85. class CAMCTreeView :
  86. public CTreeView,
  87. public CConsoleTree,
  88. public CEventSource<CTreeViewObserver>,
  89. public CMMCViewDropTarget
  90. {
  91. DECLARE_DYNCREATE (CAMCTreeView)
  92. typedef CTreeView BC;
  93. // Construction
  94. public:
  95. CAMCTreeView();
  96. // Operations
  97. public:
  98. // Inserts a node into the tree control
  99. void ResetNode(HTREEITEM hItem);
  100. HTREEITEM InsertNode(HTREEITEM hParent, HNODE hNode,
  101. HTREEITEM hInsertAfter = TVI_LAST);
  102. // Sets the folder button(+/-) on or off
  103. void SetButton(HTREEITEM hItem, BOOL bState);
  104. // Worker function to expand hItem's hNode
  105. BOOL ExpandNode(HTREEITEM hItem);
  106. void DeleteScopeTree(void);
  107. void CleanUp(void);
  108. SC ScSelectNode(MTNODEID* pIDs, int length, bool bSelectExactNode = false); // Select the given node
  109. HTREEITEM ExpandNode(MTNODEID* pIDs, int length, bool bExpand, bool bExpandVisually=true);
  110. BOOL IsSelectedItemAStaticNode(void);
  111. HRESULT AddSubFolders(HTREEITEM hti, LPRESULTDATA pResultData);
  112. HRESULT AddSubFolders(MTNODEID* pIDs, int length);
  113. CWnd * GetCtrlFromParent(HTREEITEM hti, LPCTSTR pszResultPane);
  114. void GetCountOfChildren(HTREEITEM hItem, LONG* pcChildren);
  115. void SetCountOfChildren(HTREEITEM hItem, int cChildren);
  116. void DeleteNode(HTREEITEM hti, BOOL fDeleteThis);
  117. IResultData* GetResultData() { ASSERT(m_spResultData != NULL); return m_spResultData; }
  118. IFramePrivate* GetNodeManager() { ASSERT(m_spNodeManager != NULL); return m_spNodeManager; }
  119. BOOL IsRootItemSel(void)
  120. {
  121. return (GetRootItem() == GetSelectedItem());
  122. }
  123. CTreeViewMap * GetTreeViewMap() {return &m_treeMap;} // returns the tree map for fast indexing.
  124. HNODE GetItemNode (HTREEITEM hItem) const
  125. { return (NodeFromLParam (GetItemData (hItem))); }
  126. static HNODE NodeFromLParam (LPARAM lParam)
  127. { return (reinterpret_cast<HNODE>(lParam)); }
  128. static LPARAM LParamFromNode (HNODE hNode)
  129. { return (reinterpret_cast<LPARAM>(hNode)); }
  130. public:
  131. // CConsoleTree methods
  132. virtual SC ScSetTempSelection (HTREEITEM htiSelected);
  133. virtual SC ScRemoveTempSelection ();
  134. virtual SC ScReselect ();
  135. private:
  136. bool IsTempSelectionActive() const { return (m_htiTempSelect != NULL); }
  137. HTREEITEM GetTempSelectedItem() const { return (m_htiTempSelect); }
  138. void SetTempSelectedItem(HTREEITEM htiTempSelect) { m_htiTempSelect = htiTempSelect; }
  139. HTREEITEM m_htiTempSelect;
  140. public:
  141. #ifdef DBG
  142. void DbgDisplayNodeName(HNODE hNode);
  143. void DbgDisplayNodeName(HTREEITEM hti);
  144. #endif
  145. INodeCallback* GetNodeCallback();
  146. // REVIEW: why are we caching this information here when it's already in CAMCView?
  147. void SetHasList(BOOL bHasList) {m_bHasListCurrently = bHasList;}
  148. BOOL HasList() const {return m_bHasListCurrently;}
  149. protected:
  150. SC ScGetTreeItemIconInfo(HNODE hNode, HICON *phIcon);
  151. private:
  152. BOOL m_bHasListCurrently;
  153. public:
  154. // Overrides
  155. // ClassWizard generated virtual function overrides
  156. //{{AFX_VIRTUAL(CAMCTreeView)
  157. public:
  158. virtual BOOL DestroyWindow();
  159. virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
  160. protected:
  161. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  162. virtual BOOL OnCmdMsg( UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo );
  163. virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
  164. //}}AFX_VIRTUAL
  165. // Implementation
  166. public:
  167. virtual SC ScDropOnTarget(bool bHitTestOnly, IDataObject * pDataObject, CPoint pt, bool& bCopyOperation);
  168. virtual void RemoveDropTargetHiliting();
  169. virtual ~CAMCTreeView();
  170. CAMCView* GetAMCView()
  171. {
  172. if (m_pAMCView && ::IsWindow(*m_pAMCView))
  173. return m_pAMCView;
  174. return NULL;
  175. }
  176. friend class CNodeInitObject;
  177. friend class CAMCView;
  178. protected:
  179. IFramePrivatePtr m_spNodeManager;
  180. IScopeDataPrivatePtr m_spScopeData;
  181. IHeaderCtrlPtr m_spHeaderCtrl;
  182. IResultDataPrivatePtr m_spResultData;
  183. IImageListPrivatePtr m_spRsltImageList;
  184. BOOL m_fInCleanUp;
  185. BOOL m_fInExpanding;
  186. CAMCView* m_pAMCView;
  187. CTreeViewMap m_treeMap; // fast indexing
  188. HRESULT CreateNodeManager(void);
  189. HTREEITEM GetClickedNode();
  190. private:
  191. inline IScopeTreeIter* GetScopeIterator();
  192. inline IScopeTree* GetScopeTree();
  193. void OnDeSelectNode(HNODE hNode);
  194. void InitDefListView(LPUNKNOWN pUnkResultsPane);
  195. HRESULT OnSelectNode(HTREEITEM hItem, HNODE hNode);
  196. HTREEITEM FindNode(HTREEITEM hti, MTNODEID id);
  197. HTREEITEM FindSiblingItem(HTREEITEM hti, MTNODEID id);
  198. void _DeleteNode(SDeleteNodeInfo& dni);
  199. void CollapseChildren (HTREEITEM htiParent);
  200. void OnButtonUp();
  201. CTreeFontLinker m_FontLinker;
  202. /*
  203. * this caches the text for the selected item, so we'll know whether
  204. * to fire the ScOnSelectedItemTextChanged event to observers
  205. */
  206. CString m_strSelectedItemText;
  207. // Generated message map functions
  208. protected:
  209. //{{AFX_MSG(CAMCTreeView)
  210. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  211. afx_msg void OnSelChanged(NMHDR* pNMHDR, LRESULT* pResult);
  212. afx_msg void OnSelChanging(NMHDR* pNMHDR, LRESULT* pResult);
  213. afx_msg void OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult);
  214. afx_msg void OnItemExpanding(NMHDR* pNMHDR, LRESULT* pResult);
  215. afx_msg void OnItemExpanded(NMHDR* pNMHDR, LRESULT* pResult);
  216. afx_msg void OnDestroy();
  217. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  218. afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  219. afx_msg void OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  220. afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
  221. afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
  222. afx_msg void OnBeginRDrag(NMHDR* pNMHDR, LRESULT* pResult);
  223. afx_msg void OnSetFocus(CWnd* pOldWnd);
  224. afx_msg void OnKillFocus(CWnd* pNewWnd);
  225. //}}AFX_MSG
  226. afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
  227. afx_msg void OnSelChangedWorker(NM_TREEVIEW* pnmtv, LRESULT* pResult);
  228. afx_msg void OnSelChangingWorker(NM_TREEVIEW* pnmtv, LRESULT* pResult);
  229. DECLARE_MESSAGE_MAP()
  230. private: // used for the keyboard timer
  231. class CKeyboardNavDelay : public CKeyboardNavDelayTimer
  232. {
  233. typedef CKeyboardNavDelayTimer BaseClass;
  234. public:
  235. CKeyboardNavDelay(CAMCTreeView* pTreeView);
  236. SC ScStartTimer(NMTREEVIEW* pnmtv);
  237. virtual void OnTimer();
  238. private:
  239. CAMCTreeView* const m_pTreeView;
  240. NMTREEVIEW m_nmtvSelChanged;
  241. };
  242. friend class CKeyboardNavDelay;
  243. std::auto_ptr<CKeyboardNavDelay> m_spKbdNavDelay;
  244. void SetNavigatingWithKeyboard (bool fKeyboardNav);
  245. bool IsNavigatingWithKeyboard () const
  246. {
  247. return (m_spKbdNavDelay.get() != NULL);
  248. }
  249. public:
  250. SC ScRenameScopeNode(HMTNODE hMTNode); // put the specified scope node into rename mode.
  251. public:
  252. CImageList* CreateDragImage(HTREEITEM hItem)
  253. {
  254. return GetTreeCtrl().CreateDragImage(hItem);
  255. }
  256. BOOL DeleteItem(HTREEITEM hItem)
  257. {
  258. return GetTreeCtrl().DeleteItem(hItem);
  259. }
  260. CEdit* EditLabel(HTREEITEM hItem)
  261. {
  262. return GetTreeCtrl().EditLabel(hItem);
  263. }
  264. BOOL EnsureVisible(HTREEITEM hItem)
  265. {
  266. return GetTreeCtrl().EnsureVisible(hItem);
  267. }
  268. BOOL Expand(HTREEITEM hItem, UINT nCode, bool bExpandVisually);
  269. BOOL Expand(HTREEITEM hItem, UINT nCode)
  270. {
  271. return GetTreeCtrl().Expand(hItem, nCode);
  272. }
  273. HTREEITEM GetChildItem(HTREEITEM hItem) const
  274. {
  275. return GetTreeCtrl().GetChildItem(hItem);
  276. }
  277. HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const
  278. {
  279. return GetTreeCtrl().GetNextItem(hItem, nCode);
  280. }
  281. HTREEITEM GetNextSiblingItem(HTREEITEM hItem) const
  282. {
  283. return GetTreeCtrl().GetNextSiblingItem(hItem);
  284. }
  285. HTREEITEM GetParentItem(HTREEITEM hItem) const
  286. {
  287. return GetTreeCtrl().GetParentItem(hItem);
  288. }
  289. BOOL GetItem(TV_ITEM* pItem) const
  290. {
  291. return GetTreeCtrl().GetItem(pItem);
  292. }
  293. DWORD_PTR GetItemData(HTREEITEM hItem) const
  294. {
  295. return GetTreeCtrl().GetItemData(hItem);
  296. }
  297. BOOL GetItemRect(HTREEITEM hItem, LPRECT lpRect, BOOL bTextOnly) const
  298. {
  299. return GetTreeCtrl().GetItemRect(hItem, lpRect, bTextOnly);
  300. }
  301. HTREEITEM GetSelectedItem()
  302. {
  303. return GetTreeCtrl().GetSelectedItem();
  304. }
  305. HTREEITEM InsertItem(LPTV_INSERTSTRUCT lpInsertStruct)
  306. {
  307. return GetTreeCtrl().InsertItem(lpInsertStruct);
  308. }
  309. BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask)
  310. {
  311. return GetTreeCtrl().SetItemState(hItem, nState, nStateMask);
  312. }
  313. BOOL SetItem(TV_ITEM* pItem)
  314. {
  315. return GetTreeCtrl().SetItem(pItem);
  316. }
  317. HTREEITEM HitTest(CPoint pt, UINT* pFlags = NULL) const
  318. {
  319. return GetTreeCtrl().HitTest(pt, pFlags);
  320. }
  321. HTREEITEM HitTest(TV_HITTESTINFO* pHitTestInfo) const
  322. {
  323. return GetTreeCtrl().HitTest(pHitTestInfo);
  324. }
  325. BOOL SelectItem(HTREEITEM hItem)
  326. {
  327. return GetTreeCtrl().SelectItem(hItem);
  328. }
  329. HTREEITEM GetRootItem()
  330. {
  331. return GetTreeCtrl().GetRootItem();
  332. }
  333. };
  334. #endif // __TREECTRL_H__