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.

552 lines
20 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: Node.h
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 9/16/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. #ifndef _MMC_NODE_H_
  18. #define _MMC_NODE_H_
  19. #pragma once
  20. #include "amcmsgid.h"
  21. #include "refcount.h" // for CRefCountedObject
  22. // A vector of strings to store column names
  23. typedef std::vector<tstring> TStringVector;
  24. ///////////////////////////////////////////////////////////////////////////////
  25. // Classes declared in this file
  26. class CComponent;
  27. class CDataNotifyInfo;
  28. class CNode;
  29. class CSnapInNode;
  30. ///////////////////////////////////////////////////////////////////////////////
  31. // Forward declarations
  32. class CConsoleTaskpad;
  33. class CResultItem;
  34. class CResultViewType;
  35. class CMMCClipBoardDataObject;
  36. class CViewSettingsPersistor;
  37. ///////////////////////////////////////////////////////////////////////////////
  38. // Class declarations
  39. //____________________________________________________________________________
  40. //
  41. // class: CComponent
  42. //____________________________________________________________________________
  43. //
  44. class CComponent
  45. {
  46. DECLARE_NOT_COPIABLE (CComponent);
  47. DECLARE_NOT_ASSIGNABLE(CComponent);
  48. public:
  49. // Constructor & Destructor
  50. CComponent(CSnapIn * pSnapIn);
  51. virtual ~CComponent();
  52. // Attributes
  53. const CLSID& GetCLSID() const
  54. {
  55. if (m_spSnapIn == NULL)
  56. return (GUID_NULL);
  57. return m_spSnapIn->GetSnapInCLSID();
  58. }
  59. CSnapIn* GetSnapIn(void) const
  60. {
  61. return m_spSnapIn;
  62. }
  63. IComponent* GetIComponent(void) const
  64. {
  65. return m_spIComponent;
  66. }
  67. IFramePrivate* GetIFramePrivate(void) const
  68. {
  69. return m_spIFrame;
  70. }
  71. IImageListPrivate* GetIImageListPrivate(void) const
  72. {
  73. return m_spIRsltImageList;
  74. }
  75. // Operations
  76. // Initialization
  77. HRESULT Init(IComponentData* pIComponentData, HMTNODE hMTNode, HNODE lNode,
  78. COMPONENTID nComponentID, int viewID);
  79. BOOL IsInitialized()
  80. {
  81. return (m_spIFrame != NULL);
  82. }
  83. LPUNKNOWN GetUnknownToLoad(void) const
  84. {
  85. return m_spIComponent;
  86. }
  87. // IComponent interface methods
  88. HRESULT Initialize(LPCONSOLE lpConsole);
  89. HRESULT Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LONG_PTR arg, LPARAM param);
  90. HRESULT Destroy(MMC_COOKIE cookie);
  91. HRESULT QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  92. LPDATAOBJECT* ppDataObject);
  93. HRESULT GetResultViewType(MMC_COOKIE cookie, LPOLESTR* ppszViewType, long* pViewOptions);
  94. HRESULT GetDisplayInfo(RESULTDATAITEM* pResultDataItem);
  95. // IComponent2 helper
  96. SC ScQueryDispatch(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, PPDISPATCH ppSelectedObject);
  97. void SetComponentID(COMPONENTID nID)
  98. {
  99. ASSERT(nID < 1000);
  100. m_ComponentID = nID;
  101. }
  102. COMPONENTID GetComponentID(void) const
  103. {
  104. return m_ComponentID;
  105. }
  106. void ResetComponentID(COMPONENTID id)
  107. {
  108. m_spIFrame->SetComponentID(m_ComponentID = id);
  109. }
  110. SC ScResetConsoleVerbStates ();
  111. // loaded from stream/storage; initailized with the new one; or does not need initialization
  112. bool IsIComponentInitialized()
  113. {
  114. return m_bIComponentInitialized;
  115. }
  116. // loaded from stream/storage; initailized with the new one; or does not need initialization
  117. void SetIComponentInitialized()
  118. {
  119. m_bIComponentInitialized = true;
  120. }
  121. private:
  122. // Implementation
  123. CSnapInPtr m_spSnapIn;
  124. IComponentPtr m_spIComponent;
  125. IFramePrivatePtr m_spIFrame;
  126. IImageListPrivatePtr m_spIRsltImageList;
  127. COMPONENTID m_ComponentID;
  128. bool m_bIComponentInitialized;
  129. // Helper methods
  130. void Construct(CSnapIn * pSnapIn, CComponent* pComponent);
  131. }; // class CComponent
  132. class CComponentPtrArray : public CArray<CComponent*, CComponent*>
  133. {
  134. public:
  135. void AddComponent(CComponent* pCC)
  136. {
  137. for (int i = GetUpperBound(); i >= 0; --i)
  138. {
  139. if (GetAt(i) == pCC)
  140. return;
  141. }
  142. Add(pCC);
  143. }
  144. };
  145. //____________________________________________________________________________
  146. //
  147. // class: CNode
  148. //
  149. // PURPOSE: Each master tree node class (ie CMTxxx) has a matching CNode-derived
  150. // class. The CNode-derived class objects encapsulate the view-dependent
  151. // settings of the CMTNode derived object.
  152. //
  153. //____________________________________________________________________________
  154. //
  155. class CNode
  156. {
  157. DECLARE_NOT_ASSIGNABLE(CNode);
  158. // Constructor & Destructor
  159. protected:
  160. // only from CSnapInNode
  161. CNode(CMTNode * pMTNode, CViewData* pViewData, bool fRootNode, bool fStaticNode);
  162. public:
  163. CNode(CMTNode * pMTNode, CViewData* pViewData, bool fRootNode);
  164. CNode(const CNode& other);
  165. virtual ~CNode();
  166. // converters
  167. static CNode* FromHandle (HNODE hNode);
  168. static CNode* FromResultItem (CResultItem* pri);
  169. static HNODE ToHandle (const CNode* pNode);
  170. // Attributes
  171. CViewData* GetViewData(void)const {ASSERT(m_pViewData != NULL); return m_pViewData;}
  172. int GetViewID(void) {ASSERT(m_pViewData != NULL);return m_pViewData->GetViewID();}
  173. virtual UINT GetResultImage() {return m_pMTNode->GetImage();}
  174. void SetDisplayName(LPCTSTR pName){m_pMTNode->SetDisplayName(pName);}
  175. void SetResultItem(HRESULTITEM hri){m_hri = hri;}
  176. long GetOwnerID(void) const{return m_pMTNode->GetOwnerID();}
  177. void ResetFlags();
  178. void SetExpandedAtLeastOnce();
  179. BOOL WasExpandedAtLeastOnce();
  180. void SetExpandedVisually(bool bExpanded);
  181. bool WasExpandedVisually(void);
  182. bool AllowNewWindowFromHere() const { return (m_pMTNode->AllowNewWindowFromHere()); }
  183. tstring GetDisplayName(){return m_pMTNode->GetDisplayName();}
  184. CMTNode* GetMTNode() const {return m_pMTNode;}
  185. HRESULTITEM GetResultItem() const {return m_hri;}
  186. virtual BOOL NeedsViewToBePersisted(void){return FALSE;}
  187. virtual CComponent* GetComponent(COMPONENTID nID);
  188. CComponent* GetPrimaryComponent(void);
  189. HRESULT InitComponents();
  190. // Overridables
  191. SC ScGetResultPane(CResultViewType &rvt, GUID *pGuidTaskpadID);
  192. BOOL IsDynamicNode() const {return !IsStaticNode();}
  193. BOOL IsStaticNode() const {return (m_fStaticNode);}
  194. BOOL IsConsoleRoot(){return (GetMTNode()->Parent() == NULL);}
  195. BOOL IsRootNode() const {return m_fRootNode;}
  196. virtual LPUNKNOWN GetControl(CLSID& clsid);
  197. virtual LPUNKNOWN GetControl(LPUNKNOWN pUnkOCX);
  198. virtual void SetControl(CLSID& clsid, IUnknown* pUnknown);
  199. virtual void SetControl(LPUNKNOWN pUnkOCX, IUnknown* pUnknown);
  200. CSnapIn* GetPrimarySnapIn(void) {return GetPrimaryComponent()->GetSnapIn();}
  201. BOOL IsInitialized(void) {return !m_bInitComponents;}
  202. IUnknown* GetControlbarsCache(void)
  203. {return m_pViewData->GetControlbarsCache();}
  204. HRESULT OnSelect(LPUNKNOWN lpView, BOOL bSelect, BOOL bResultPaneIsWeb);
  205. HRESULT OnScopeSelect(bool bSelect, SELECTIONINFO* pSelInfo);
  206. HRESULT OnListPad(LONG_PTR arg, LPARAM param);
  207. HRESULT IsTargetNode(CNode *pNodeTest) {return E_FAIL;} // do not change.
  208. HRESULT OnExpand(bool fExpand);
  209. HRESULT OnGetPrimaryTask(IExtendTaskPad **ppExtendTaskPad);
  210. IFramePrivate * GetIFramePrivate();
  211. HRESULT GetTaskEnumerator(LPOLESTR pszTaskGroup, IEnumTASK** ppEnumTask);
  212. HRESULT GetListPadInfo(IExtendTaskPad* pExtendTaskPad, LPOLESTR szTaskGroup,
  213. MMC_ILISTPAD_INFO* pIListPadInfo);
  214. void ResetControlbars(BOOL bSelect, SELECTIONINFO* pSelInfo);
  215. void ResetVerbSets(BOOL bSelect, SELECTIONINFO* pSelInfo);
  216. HRESULT GetDataInfo(BOOL bSelect, SELECTIONINFO* pSelInfo, CDataNotifyInfo* pDNI);
  217. SC ScInitializeVerbs (bool bSelect, SELECTIONINFO* pSelInfo);
  218. void OnTaskNotify(LONG_PTR arg, LPARAM param);
  219. virtual void OnWebContextMenu() {};
  220. LPARAM GetUserParam(void);
  221. HRESULT GetDispInfoForListItem(LV_ITEMW* plvi);
  222. HRESULT GetDispInfo(LV_ITEMW* plvi);
  223. HRESULT OnColumnClicked(LONG_PTR nCol);
  224. HRESULT OnInitOCX(IUnknown* pUnk);
  225. HRESULT OnCacheHint(int nStartIndex, int nEndIndex);
  226. HRESULT SendShowEvent(BOOL bSelect);
  227. HRESULT OnColumnsChange(CColumnInfoList& colInfoList);
  228. SC ScSetViewExtension(GUID *pGuidViewId, bool bUseDefaultTaskpad, bool bSetViewSettingsDirty);
  229. SC ScGetDataObject(bool bScopePane, LPARAM lResultItemCookie, bool& bScopeItem, LPDATAOBJECT* ppDataObject, CComponent **ppCComponent = NULL, CNode **ppOwnerNode = NULL);
  230. SC ScGetPropertyFromINodeProperties(LPDATAOBJECT pDataObject, BOOL bForScopeItem, LPARAM resultItemParam, BSTR bstrPropertyName, PBSTR pbstrPropertyValue);
  231. SC ScExecuteShellCommand(BSTR Command, BSTR Directory, BSTR Parameters, BSTR WindowState);
  232. SC ScGetDropTargetDataObject(bool bScope, LPARAM lResultItemCookie, LPDATAOBJECT *ppDataObject);
  233. CSnapInNode* GetStaticParent(void);
  234. HRESULT QueryDataObject(DATA_OBJECT_TYPES type, LPDATAOBJECT* ppdtobj);
  235. HRESULT GetNodeType(GUID* pGuid);
  236. SC ScSetupTaskpad(GUID *pGuidTaskpadID);
  237. HRESULT RestoreSort(INT nCol, DWORD dwSortOptions);
  238. SC ScRestoreSortFromPersistedData();
  239. SC ScSaveSortData (int nCol, DWORD dwOptions);
  240. SC ScGetSnapinAndColumnDataID(GUID& snapinGuid, CXMLAutoBinary& columnID);
  241. SC ScRestoreResultView(const CResultViewType& rvt);
  242. SC ScRestoreViewMode();
  243. SC ScSaveColumnInfoList(CColumnInfoList& columnInfoList);
  244. const CLSID& GetPrimarySnapInCLSID(void);
  245. HRESULT ExtractColumnConfigID(IDataObject* pDataObj, HGLOBAL& phGlobal);
  246. CLIPFORMAT GetColumnConfigIDCF();
  247. void SetPrimaryComponent(CComponent* p) { ASSERT(m_pPrimaryComponent == NULL); m_pPrimaryComponent = p; }
  248. SC ScGetCurrentColumnData( CColumnInfoList& columnInfoList, TStringVector& strColNames);
  249. SC ScShowColumn(int iColIndex, bool bShow);
  250. SC ScSetUpdatedColumnData( CColumnInfoList& oldColumnInfoList, CColumnInfoList& newColumnInfoList);
  251. SC ScGetSortColumn(int *piSortCol);
  252. SC ScSetSortColumn(int iSortCol, bool bAscending);
  253. SC ScGetViewExtensions(CViewExtInsertIterator it);
  254. HRESULT ShowStandardListView();
  255. HRESULT OnActvate(LONG_PTR lActivate);
  256. HRESULT OnMinimize(LONG_PTR fMinimized);
  257. void Reset();
  258. void SetInitComponents(BOOL b) { m_bInitComponents = b; }
  259. void OnColumns();
  260. /***************************************************************************\
  261. *
  262. * CLASS: CDataObjectCleanup
  263. *
  264. * PURPOSE: Groups methods to register/trigger data object clenup when
  265. * CNode, which data is put to data object goes away
  266. *
  267. * USAGE: Used from CMMCClipBoardDataObject to register nodes put to it
  268. * And used from ~CNode to trigger the cleanup
  269. *
  270. \***************************************************************************/
  271. class CDataObjectCleanup
  272. {
  273. public:
  274. static SC ScRegisterNode(CNode *pNode, CMMCClipBoardDataObject *pObject);
  275. static SC ScUnadviseDataObject(CMMCClipBoardDataObject *pObject, bool bForceDataObjectCleanup = true);
  276. static SC ScUnadviseNode(CNode *pNode);
  277. // mapping CNode to data object which contains it's data
  278. typedef std::multimap<CNode *, CMMCClipBoardDataObject *> CMapOfNodes;
  279. private:
  280. static CMapOfNodes s_mapOfNodes;
  281. };
  282. // CViewSettingsPersistor's persistence interfaces.
  283. static SC ScQueryViewSettingsPersistor(IPersistStream **ppStream);
  284. static SC ScQueryViewSettingsPersistor(CXMLObject **ppXMLObject);
  285. static SC ScOnDocumentClosing();
  286. static SC ScDeleteViewSettings(int nVieWID);
  287. static SC ScSetFavoriteViewSettings (int nViewID, const CBookmark& bookmark, const CViewSettings& viewSettings);
  288. SC ScSetViewMode (ULONG ulViewMode);
  289. SC ScSetTaskpadID(const GUID& guidTaskpad, bool bSetDirty);
  290. // Implementation
  291. private:
  292. HRESULT DeepNotify (MMC_NOTIFY_TYPE event, LONG_PTR arg, LPARAM param);
  293. SC ScInitializeViewExtension(const CLSID& clsid, CViewData *pViewData);
  294. void CommonConstruct();
  295. // Get & Set persisted ViewSettings data.
  296. SC ScGetTaskpadID(GUID& guidTaskpad);
  297. SC ScGetConsoleTaskpad (const GUID& guidTaskpad, CConsoleTaskpad **ppTaskpad);
  298. SC ScGetViewMode (ULONG& ulViewMode);
  299. SC ScGetResultViewType (CResultViewType& rvt);
  300. SC ScSetResultViewType (const CResultViewType& rvt);
  301. private:
  302. CMTNode* const m_pMTNode; // ptr back to the master node.
  303. HRESULTITEM m_hri; // this node's result item handle
  304. CViewData* m_pViewData;
  305. DWORD m_dwFlags;
  306. enum
  307. {
  308. flag_expanded_at_least_once = 0x00000001,
  309. flag_expanded_visually = 0x00000002,
  310. };
  311. CComponent* m_pPrimaryComponent;
  312. bool m_bInitComponents : 1;
  313. const bool m_fRootNode : 1;
  314. const bool m_fStaticNode : 1;
  315. static CComObject<CViewSettingsPersistor>* m_pViewSettingsPersistor;
  316. };
  317. //____________________________________________________________________________
  318. //
  319. // class: COCX
  320. //
  321. // Purpose: Store the IUnknown ptr of OCX wrapper and an identifier for
  322. // the OCX. The identifier may be CLSID of the OCX or
  323. // the IUnknown ptr of the OCX.
  324. //
  325. // In essence a OCXWrapper can be saved using CLSID of OCX as
  326. // the key (IComponent::GetResultViewType) or IUnknown* of OCX
  327. // as the key (IComponent2::GetResultViewType2).
  328. //
  329. // Therefore we have overloaded version of SetControl below.
  330. //
  331. //____________________________________________________________________________
  332. //
  333. class COCX
  334. {
  335. public:
  336. // Constructor & Destructor
  337. COCX(void);
  338. ~COCX(void);
  339. // Attributes
  340. void SetControl(CLSID& clsid, IUnknown* pUnknown);
  341. BOOL IsControlCLSID(CLSID clsid) { return IsEqualCLSID(clsid, m_clsid); }
  342. IUnknown* GetControlUnknown() { return m_spOCXWrapperUnknown;}
  343. void SetControl(LPUNKNOWN pUnkOCX, LPUNKNOWN pUnkOCXWrapper);
  344. //
  345. // Compare the IUnknown given and the one stored.
  346. //
  347. bool IsSameOCXIUnknowns(IUnknown *pOtherOCXUnknown) { return m_spOCXUnknown.IsEqualObject(pOtherOCXUnknown);}
  348. // Implementation
  349. private:
  350. // Only one of CLSID or m_spOCXUnknown is valid, see class purpose for details.
  351. CLSID m_clsid;
  352. CComPtr<IUnknown> m_spOCXUnknown;
  353. CComPtr<IUnknown> m_spOCXWrapperUnknown;
  354. }; // COCX
  355. //____________________________________________________________________________
  356. //
  357. // class: CSnapInNode
  358. //____________________________________________________________________________
  359. //
  360. class CSnapInNode : public CNode
  361. {
  362. public:
  363. // Constructor & Destructor
  364. CSnapInNode(CMTSnapInNode* pMTNode, CViewData* pViewData, bool fRootNode);
  365. CSnapInNode(const CSnapInNode& other);
  366. ~CSnapInNode();
  367. // Attributes
  368. virtual UINT GetResultImage();
  369. virtual BOOL NeedsViewToBePersisted(void) { return TRUE; }
  370. virtual void SetControl(CLSID& clsid, IUnknown* pUnknown);
  371. virtual LPUNKNOWN GetControl(CLSID& clsid);
  372. void CloseControls() { GetOCXArray().RemoveAll(); }
  373. virtual void SetControl(LPUNKNOWN pUnkOCX, IUnknown* pUnknown);
  374. virtual LPUNKNOWN GetControl(LPUNKNOWN pUnkOCX);
  375. CComponentArray& GetComponentArray(void) { return m_spData->GetComponentArray(); }
  376. // Operations
  377. // User interactions
  378. BOOL Activate(LPUNKNOWN pUnkResultsPane);
  379. BOOL DeActivate(HNODE hNode);
  380. BOOL Show(HNODE hNode);
  381. void Reset();
  382. int GetNumberOfComponents()
  383. {
  384. return GetComponentArray().size();
  385. }
  386. void AddComponentToArray(CComponent* pCC);
  387. CComponent* CreateComponent(CSnapIn* pSnapIn, int nID);
  388. CComponent* GetComponent(const CLSID& clsid);
  389. virtual CComponent* GetComponent(COMPONENTID nID);
  390. void DeleteComponent(COMPONENTID nID)
  391. {
  392. ASSERT(nID >= 0);
  393. int iMax = GetComponentArray().size() -1;
  394. ASSERT(nID <= iMax);
  395. if (nID < iMax)
  396. {
  397. delete GetComponentArray()[nID];
  398. GetComponentArray()[nID] = GetComponentArray()[iMax];
  399. GetComponentArray()[iMax] = 0;
  400. GetComponentArray()[iMax]->ResetComponentID(nID);
  401. }
  402. GetComponentArray().resize(iMax);
  403. }
  404. void SetResultImageList (IImageListPrivate* pImageList) { m_spData->SetImageList(pImageList); }
  405. // Implementation
  406. private:
  407. class CDataImpl
  408. {
  409. public:
  410. CDataImpl() :
  411. m_pImageList(NULL)
  412. {}
  413. ~CDataImpl()
  414. {
  415. Reset();
  416. }
  417. void Reset()
  418. {
  419. for (int i=0; i < m_ComponentArray.size(); i++)
  420. delete m_ComponentArray[i];
  421. m_ComponentArray.clear();
  422. }
  423. private:
  424. IImageListPrivate* m_pImageList; // result image list
  425. // Components array.
  426. CComponentArray m_ComponentArray;
  427. CArray<COCX, COCX&> m_rgOCX;
  428. public:
  429. void SetImageList(IImageListPrivate *pImageList)
  430. {m_pImageList = pImageList;}
  431. IImageListPrivate * GetImageList() {return m_pImageList;}
  432. CComponentArray & GetComponentArray(){return m_ComponentArray;}
  433. CArray<COCX, COCX&> & GetOCXArray() {return m_rgOCX;}
  434. }; // CSnapInNode::CDataImpl
  435. typedef CRefCountedObject<CDataImpl> CData;
  436. CData::SmartPtr m_spData;
  437. IImageListPrivate * GetImageList() {return m_spData->GetImageList();}
  438. CArray<COCX, COCX&> & GetOCXArray() {return m_spData->GetOCXArray();}
  439. }; // CSnapInNode
  440. #include "node.inl"
  441. #endif // _MMC_NODE_H_