Leaked source code of windows server 2003
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.

399 lines
13 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. protected:
  160. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  161. virtual BOOL OnCmdMsg( UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo );
  162. virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
  163. //}}AFX_VIRTUAL
  164. // Implementation
  165. public:
  166. virtual SC ScDropOnTarget(bool bHitTestOnly, IDataObject * pDataObject, CPoint pt, bool& bCopyOperation);
  167. virtual void RemoveDropTargetHiliting();
  168. virtual ~CAMCTreeView();
  169. CAMCView* GetAMCView()
  170. {
  171. if (m_pAMCView && ::IsWindow(*m_pAMCView))
  172. return m_pAMCView;
  173. return NULL;
  174. }
  175. friend class CNodeInitObject;
  176. friend class CAMCView;
  177. protected:
  178. IFramePrivatePtr m_spNodeManager;
  179. IScopeDataPrivatePtr m_spScopeData;
  180. IHeaderCtrlPtr m_spHeaderCtrl;
  181. IResultDataPrivatePtr m_spResultData;
  182. IImageListPrivatePtr m_spRsltImageList;
  183. BOOL m_fInCleanUp;
  184. BOOL m_fInExpanding;
  185. CAMCView* m_pAMCView;
  186. CTreeViewMap m_treeMap; // fast indexing
  187. HRESULT CreateNodeManager(void);
  188. HTREEITEM GetClickedNode();
  189. private:
  190. inline IScopeTreeIter* GetScopeIterator();
  191. inline IScopeTree* GetScopeTree();
  192. void OnDeSelectNode(HNODE hNode);
  193. void InitDefListView(LPUNKNOWN pUnkResultsPane);
  194. HRESULT OnSelectNode(HTREEITEM hItem, HNODE hNode);
  195. HTREEITEM FindNode(HTREEITEM hti, MTNODEID id);
  196. HTREEITEM FindSiblingItem(HTREEITEM hti, MTNODEID id);
  197. void _DeleteNode(SDeleteNodeInfo& dni);
  198. void CollapseChildren (HTREEITEM htiParent);
  199. void OnButtonUp();
  200. CTreeFontLinker m_FontLinker;
  201. /*
  202. * this caches the text for the selected item, so we'll know whether
  203. * to fire the ScOnSelectedItemTextChanged event to observers
  204. */
  205. CString m_strSelectedItemText;
  206. // Generated message map functions
  207. protected:
  208. //{{AFX_MSG(CAMCTreeView)
  209. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  210. afx_msg void OnSelChanged(NMHDR* pNMHDR, LRESULT* pResult);
  211. afx_msg void OnSelChanging(NMHDR* pNMHDR, LRESULT* pResult);
  212. afx_msg void OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult);
  213. afx_msg void OnItemExpanding(NMHDR* pNMHDR, LRESULT* pResult);
  214. afx_msg void OnItemExpanded(NMHDR* pNMHDR, LRESULT* pResult);
  215. afx_msg void OnDestroy();
  216. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  217. afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  218. afx_msg void OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  219. afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
  220. afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
  221. afx_msg void OnBeginRDrag(NMHDR* pNMHDR, LRESULT* pResult);
  222. afx_msg void OnSetFocus(CWnd* pOldWnd);
  223. afx_msg void OnKillFocus(CWnd* pNewWnd);
  224. //}}AFX_MSG
  225. afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
  226. afx_msg void OnSelChangedWorker(NM_TREEVIEW* pnmtv, LRESULT* pResult);
  227. afx_msg void OnSelChangingWorker(NM_TREEVIEW* pnmtv, LRESULT* pResult);
  228. DECLARE_MESSAGE_MAP()
  229. private: // used for the keyboard timer
  230. class CKeyboardNavDelay : public CKeyboardNavDelayTimer
  231. {
  232. typedef CKeyboardNavDelayTimer BaseClass;
  233. public:
  234. CKeyboardNavDelay(CAMCTreeView* pTreeView);
  235. SC ScStartTimer(NMTREEVIEW* pnmtv);
  236. virtual void OnTimer();
  237. private:
  238. CAMCTreeView* const m_pTreeView;
  239. NMTREEVIEW m_nmtvSelChanged;
  240. };
  241. friend class CKeyboardNavDelay;
  242. std::auto_ptr<CKeyboardNavDelay> m_spKbdNavDelay;
  243. void SetNavigatingWithKeyboard (bool fKeyboardNav);
  244. bool IsNavigatingWithKeyboard () const
  245. {
  246. return (m_spKbdNavDelay.get() != NULL);
  247. }
  248. public:
  249. SC ScRenameScopeNode(HMTNODE hMTNode); // put the specified scope node into rename mode.
  250. public:
  251. CImageList* CreateDragImage(HTREEITEM hItem)
  252. {
  253. return GetTreeCtrl().CreateDragImage(hItem);
  254. }
  255. BOOL DeleteItem(HTREEITEM hItem)
  256. {
  257. return GetTreeCtrl().DeleteItem(hItem);
  258. }
  259. CEdit* EditLabel(HTREEITEM hItem)
  260. {
  261. return GetTreeCtrl().EditLabel(hItem);
  262. }
  263. BOOL EnsureVisible(HTREEITEM hItem)
  264. {
  265. return GetTreeCtrl().EnsureVisible(hItem);
  266. }
  267. BOOL Expand(HTREEITEM hItem, UINT nCode, bool bExpandVisually);
  268. BOOL Expand(HTREEITEM hItem, UINT nCode)
  269. {
  270. return GetTreeCtrl().Expand(hItem, nCode);
  271. }
  272. HTREEITEM GetChildItem(HTREEITEM hItem) const
  273. {
  274. return GetTreeCtrl().GetChildItem(hItem);
  275. }
  276. HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const
  277. {
  278. return GetTreeCtrl().GetNextItem(hItem, nCode);
  279. }
  280. HTREEITEM GetNextSiblingItem(HTREEITEM hItem) const
  281. {
  282. return GetTreeCtrl().GetNextSiblingItem(hItem);
  283. }
  284. HTREEITEM GetParentItem(HTREEITEM hItem) const
  285. {
  286. return GetTreeCtrl().GetParentItem(hItem);
  287. }
  288. BOOL GetItem(TV_ITEM* pItem) const
  289. {
  290. return GetTreeCtrl().GetItem(pItem);
  291. }
  292. DWORD_PTR GetItemData(HTREEITEM hItem) const
  293. {
  294. return GetTreeCtrl().GetItemData(hItem);
  295. }
  296. BOOL GetItemRect(HTREEITEM hItem, LPRECT lpRect, BOOL bTextOnly) const
  297. {
  298. return GetTreeCtrl().GetItemRect(hItem, lpRect, bTextOnly);
  299. }
  300. HTREEITEM GetSelectedItem()
  301. {
  302. return GetTreeCtrl().GetSelectedItem();
  303. }
  304. HTREEITEM InsertItem(LPTV_INSERTSTRUCT lpInsertStruct)
  305. {
  306. return GetTreeCtrl().InsertItem(lpInsertStruct);
  307. }
  308. BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask)
  309. {
  310. return GetTreeCtrl().SetItemState(hItem, nState, nStateMask);
  311. }
  312. BOOL SetItem(TV_ITEM* pItem)
  313. {
  314. return GetTreeCtrl().SetItem(pItem);
  315. }
  316. HTREEITEM HitTest(CPoint pt, UINT* pFlags = NULL) const
  317. {
  318. return GetTreeCtrl().HitTest(pt, pFlags);
  319. }
  320. HTREEITEM HitTest(TV_HITTESTINFO* pHitTestInfo) const
  321. {
  322. return GetTreeCtrl().HitTest(pHitTestInfo);
  323. }
  324. BOOL SelectItem(HTREEITEM hItem)
  325. {
  326. return GetTreeCtrl().SelectItem(hItem);
  327. }
  328. HTREEITEM GetRootItem()
  329. {
  330. return GetTreeCtrl().GetRootItem();
  331. }
  332. };
  333. #endif // __TREECTRL_H__