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.

510 lines
15 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: nodeinit.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // NodeInit.h : Declaration of the CNodeInitObject
  11. #ifndef _NODEINIT_H_
  12. #define _NODEINIT_H_
  13. class CMenuItem;
  14. class SnapinStruct;
  15. class CCommandSink;
  16. class CImageIndexMap;
  17. class CMTNode;
  18. class CNode;
  19. class CSnapIn;
  20. class CConsoleFrame;
  21. class CConsoleView;
  22. class CConsoleStatusBar;
  23. class CContextMenu;
  24. class CMenuItem;
  25. interface IExtendContextMenu;
  26. typedef CList<CMenuItem*, CMenuItem*> MenuItemList;
  27. typedef CList<SnapinStruct*, SnapinStruct*> SnapinStructList;
  28. typedef long MENU_OWNER_ID;
  29. /////////////////////////////////////////////////////////////////////////////
  30. // NodeMgr
  31. #include <pshpack8.h>
  32. class CNodeInitObject :
  33. public IFramePrivate,
  34. public IHeaderCtrlPrivate,
  35. public IContextMenuProvider,
  36. public IResultDataPrivate,
  37. public IScopeDataPrivate,
  38. public IImageListPrivate,
  39. public ISupportErrorInfo,
  40. public IDisplayHelp,
  41. public IStringTable,
  42. public CPropertySheetProvider,
  43. public CColumnData,
  44. public CComObjectRoot,
  45. public CComCoClass<CNodeInitObject, &CLSID_NodeInit>
  46. {
  47. // Constructor/Destructor
  48. public:
  49. CNodeInitObject();
  50. ~CNodeInitObject();
  51. friend CColumnData;
  52. BEGIN_COM_MAP(CNodeInitObject)
  53. COM_INTERFACE_ENTRY(IFramePrivate)
  54. COM_INTERFACE_ENTRY(IConsole)
  55. COM_INTERFACE_ENTRY(IConsole2)
  56. COM_INTERFACE_ENTRY(IConsole3)
  57. COM_INTERFACE_ENTRY(IHeaderCtrl)
  58. COM_INTERFACE_ENTRY(IHeaderCtrl2)
  59. COM_INTERFACE_ENTRY(IHeaderCtrlPrivate)
  60. COM_INTERFACE_ENTRY(IContextMenuProvider)
  61. // THis interface used to be exposed on this class, and removing it may
  62. // expose compatibility problems [vivekj]
  63. // COM_INTERFACE_ENTRY(IContextMenuCallback)
  64. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  65. COM_INTERFACE_ENTRY(IResultData)
  66. COM_INTERFACE_ENTRY(IResultData2)
  67. COM_INTERFACE_ENTRY(IResultDataPrivate)
  68. COM_INTERFACE_ENTRY(IConsoleNameSpace)
  69. COM_INTERFACE_ENTRY(IConsoleNameSpace2)
  70. COM_INTERFACE_ENTRY(IScopeDataPrivate)
  71. COM_INTERFACE_ENTRY(IImageList)
  72. COM_INTERFACE_ENTRY(IImageListPrivate)
  73. COM_INTERFACE_ENTRY(IPropertySheetProviderPrivate)
  74. COM_INTERFACE_ENTRY(IPropertySheetProvider)
  75. COM_INTERFACE_ENTRY(IPropertySheetCallback)
  76. COM_INTERFACE_ENTRY(IPropertySheetNotify)
  77. COM_INTERFACE_ENTRY(IDisplayHelp)
  78. COM_INTERFACE_ENTRY(IStringTable)
  79. COM_INTERFACE_ENTRY_FUNC(IID_IColumnData, 0, ColumnInterfaceFunc)
  80. END_COM_MAP()
  81. // Use DECLARE_NOT_AGGREGATABLE(CNodeInitObject) if you don't want your object
  82. // to support aggregation
  83. DECLARE_AGGREGATABLE(CNodeInitObject)
  84. DECLARE_MMC_OBJECT_REGISTRATION (
  85. g_szMmcndmgrDll, // implementing DLL
  86. CLSID_NodeInit, // CLSID
  87. _T("NodeInit 1.0 Object"), // class name
  88. _T("NODEMGR.NodeInitObject.1"), // ProgID
  89. _T("NODEMGR.NodeInitObject")) // version-independent ProgID
  90. IMPLEMENTS_SNAPIN_NAME_FOR_DEBUG()
  91. public:
  92. // ISupportsErrorInfo
  93. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  94. public:
  95. #ifdef DBG
  96. int dbg_cRef;
  97. ULONG InternalAddRef()
  98. {
  99. ++dbg_cRef;
  100. return CComObjectRoot::InternalAddRef();
  101. }
  102. ULONG InternalRelease()
  103. {
  104. --dbg_cRef;
  105. return CComObjectRoot::InternalRelease();
  106. }
  107. int dbg_InstID;
  108. #endif // DBG
  109. // IFramePrivate
  110. public:
  111. STDMETHOD(CreateScopeImageList)(REFCLSID refClsidSnapIn);
  112. STDMETHOD(SetResultView)(LPUNKNOWN pUnknown);
  113. STDMETHOD(IsResultViewSet)(BOOL* pbIsLVSet);
  114. STDMETHOD(SetTaskPadList)(LPUNKNOWN pUnknown);
  115. STDMETHOD(GetComponentID)(COMPONENTID* lpComponentID);
  116. STDMETHOD(SetComponentID)(COMPONENTID id);
  117. STDMETHOD(SetNode)(HMTNODE hMTNode, HNODE hNode = NULL);
  118. STDMETHOD(QueryScopeTree)(IScopeTree** ppScopeTree);
  119. STDMETHOD(SetScopeTree)(IScopeTree* pScopeTree);
  120. STDMETHOD(SetComponent)(LPCOMPONENT lpComponent);
  121. STDMETHOD(SetUsedByExtension)(BOOL bExtension);
  122. STDMETHOD(IsUsedByExtension)(void);
  123. STDMETHOD(GetMainWindow)(HWND* phwnd);
  124. HWND GetMainWindow()
  125. {
  126. ASSERT(m_spScopeTree != NULL);
  127. if (m_spScopeTree == NULL)
  128. return NULL;
  129. CScopeTree* const pst = dynamic_cast<CScopeTree*>(&*m_spScopeTree);
  130. ASSERT(pst != NULL);
  131. return (pst != NULL && m_spScopeTree != NULL) ?
  132. pst->GetMainWindow() : NULL;
  133. }
  134. CMTNode* GetMTNode() { return m_pMTNode;}
  135. STDMETHOD(InitViewData)(LONG_PTR lViewData);
  136. STDMETHOD(CleanupViewData)(LONG_PTR lViewData);
  137. STDMETHOD(ResetSortParameters)();
  138. STDMETHOD(ReleaseCachedOleObjects)();
  139. // IConsole2
  140. public:
  141. STDMETHOD(Expand)(HSCOPEITEM hItem, BOOL bExpand);
  142. STDMETHOD(IsTaskpadViewPreferred)();
  143. STDMETHOD(SetStatusText)(LPOLESTR pszStatusText);
  144. // IConsole3
  145. public:
  146. STDMETHOD(RenameScopeItem)(HSCOPEITEM hScopeItem);
  147. protected:
  148. static IScopeTreePtr m_spScopeTree;
  149. IConsoleVerbPtr m_spConsoleVerb;
  150. CMTNode* m_pMTNode;
  151. CNode* m_pNode;
  152. BOOL m_bExtension;
  153. // IFrame
  154. public:
  155. STDMETHOD(QueryResultView)(LPUNKNOWN* ppIUnknown);
  156. STDMETHOD(SetHeader)(IHeaderCtrl* pHeader);
  157. STDMETHOD(SetToolbar)(IToolbar* pToolbar);
  158. STDMETHOD(QueryScopeImageList)(LPIMAGELIST *ppImageList);
  159. STDMETHOD(QueryResultImageList)(LPIMAGELIST *ppImageList);
  160. STDMETHOD(MessageBox)(LPCWSTR lpszText, LPCWSTR lpszTitle, UINT fuStyle, int* piRetval);
  161. STDMETHOD(UpdateAllViews)(LPDATAOBJECT lpDataObject, LPARAM data, LONG_PTR hint);
  162. STDMETHOD(QueryConsoleVerb)(LPCONSOLEVERB* ppConsoleVerb);
  163. STDMETHOD(SelectScopeItem)(HSCOPEITEM hScopeItem);
  164. STDMETHOD(NewWindow)(HSCOPEITEM hScopeItem, unsigned long lOptions);
  165. // IFrames members
  166. protected:
  167. LPUNKNOWN m_pLVImage;
  168. LPUNKNOWN m_pTVImage;
  169. LPUNKNOWN m_pToolbar;
  170. LPIMAGELISTPRIVATE m_pImageListPriv;
  171. COMPONENTID m_componentID;
  172. IComponentPtr m_spComponent;
  173. IUnknownPtr m_spResultViewUnk; // IUnknown for the result view
  174. public:
  175. CConsoleFrame* GetConsoleFrame() const;
  176. CConsoleView* GetConsoleView(bool fDefaultToActive = true) const;
  177. CConsoleStatusBar* GetStatusBar (bool fDefaultToActive = true) const;
  178. ///////////////////////////////////////////////////////////////////////////////
  179. // IHeaderCtrl interface
  180. protected:
  181. STDMETHOD(InsertColumn)(int nCol, LPCWSTR lpszTitle, int nFormat, int nWidth);
  182. STDMETHOD(DeleteColumn)(int nCol);
  183. STDMETHOD(SetColumnWidth)(int nCol, int nWidth);
  184. STDMETHOD(GetColumnText)(int nCol, LPWSTR* pText);
  185. STDMETHOD(SetColumnText)(int nCol, LPCWSTR title);
  186. STDMETHOD(GetColumnWidth)(int nCol, int* pWidth);
  187. // IHeaderCtrl2 interface
  188. STDMETHOD(SetChangeTimeOut)(unsigned long uTimeout);
  189. STDMETHOD(SetColumnFilter)(UINT nColumn, DWORD dwType, MMC_FILTERDATA* pFilterData);
  190. STDMETHOD(GetColumnFilter)(UINT nColumn, LPDWORD pType, MMC_FILTERDATA* pFilterData);
  191. // IHeaderCtrlPrivate interface.
  192. STDMETHOD(GetColumnCount)(INT* pnCol);
  193. STDMETHOD(GetColumnInfoList)(/*[out]*/ CColumnInfoList *pColumnsList);
  194. STDMETHOD(ModifyColumns)(/*[in]*/ const CColumnInfoList& columnsList);
  195. STDMETHOD(GetDefaultColumnInfoList)(/*[out]*/ CColumnInfoList& columnsList);
  196. private:
  197. CCLVSortParams m_sortParams;
  198. ///////////////////////////////////////////////////////////////////////////////
  199. // IDisplayHelp interface
  200. protected:
  201. STDMETHOD(ShowTopic)(LPOLESTR pszHelpTopic);
  202. ///////////////////////////////////////////////////////////////////////////////
  203. // IStringTable interface
  204. protected:
  205. STDMETHOD(AddString) (LPCOLESTR pszAdd, MMC_STRING_ID* pID);
  206. STDMETHOD(GetString) (MMC_STRING_ID id, ULONG cchBuffer, LPOLESTR lpBuffer, ULONG* pcchOut);
  207. STDMETHOD(GetStringLength) (MMC_STRING_ID id, ULONG* pcchString);
  208. STDMETHOD(DeleteString) (MMC_STRING_ID id);
  209. STDMETHOD(DeleteAllStrings) ();
  210. STDMETHOD(FindString) (LPCOLESTR pszFind, MMC_STRING_ID* pID);
  211. STDMETHOD(Enumerate) (IEnumString** ppEnum);
  212. HRESULT GetSnapinCLSID (CLSID& pclsid) const;
  213. ///////////////////////////////////////////////////////////////////////////////
  214. // IResultDataPrivate interface
  215. protected:
  216. IMMCListViewPtr m_spListViewPrivate;
  217. STDMETHOD(Arrange)(long style);
  218. STDMETHOD(InsertItem)(LPRESULTDATAITEM item);
  219. STDMETHOD(DeleteItem)(HRESULTITEM itemID, int nCol);
  220. STDMETHOD(FindItemByLParam)(LPARAM lParam, HRESULTITEM *pItemID);
  221. STDMETHOD(DeleteAllRsltItems)();
  222. STDMETHOD(SetItem)(LPRESULTDATAITEM item);
  223. STDMETHOD(GetItem)(LPRESULTDATAITEM item);
  224. STDMETHOD(ModifyItemState)(int nIndex, HRESULTITEM ItemID, UINT uAdd, UINT uRemove);
  225. STDMETHOD(ModifyViewStyle)(MMC_RESULT_VIEW_STYLE add, MMC_RESULT_VIEW_STYLE remove);
  226. STDMETHOD(GetNextItem)(LPRESULTDATAITEM item);
  227. STDMETHOD(SetViewMode)(LONG nViewMode);
  228. STDMETHOD(GetViewMode)(LONG* nViewMode);
  229. STDMETHOD(ResetResultData)();
  230. STDMETHOD(GetListStyle)(long * pStyle);
  231. STDMETHOD(SetListStyle)(long Style);
  232. STDMETHOD(UpdateItem)(HRESULTITEM itemID);
  233. STDMETHOD(Sort)(int nCol, DWORD dwSortOptions, LPARAM lUserParam);
  234. STDMETHOD(InternalSort)(INT nCol, DWORD dwSortOptions, LPARAM lUserParam, BOOL bColumnClicked);
  235. STDMETHOD(SetDescBarText)(LPOLESTR DescText);
  236. STDMETHOD(SetItemCount)(int nItemCount, DWORD dwOptions);
  237. STDMETHOD(SetLoadMode)(BOOL bState);
  238. STDMETHOD(GetSortColumn)(INT* pnCol);
  239. STDMETHOD(GetSortDirection)(BOOL* pbAscending);
  240. // IResultData2
  241. STDMETHOD(RenameResultItem)(HRESULTITEM itemID);
  242. ///////////////////////////////////////////////////////////////////////////////
  243. // IScopeData interface
  244. protected:
  245. // IConsoleNameSpace methods
  246. STDMETHOD(InsertItem)(LPSCOPEDATAITEM item);
  247. STDMETHOD(DeleteItem)(HSCOPEITEM hItem, long fDeleteThis);
  248. STDMETHOD(SetItem)(LPSCOPEDATAITEM item);
  249. STDMETHOD(GetItem)(LPSCOPEDATAITEM item);
  250. STDMETHOD(GetChildItem)(HSCOPEITEM item, HSCOPEITEM* pItemChild,
  251. MMC_COOKIE* pCookie);
  252. STDMETHOD(GetNextItem)(HSCOPEITEM item, HSCOPEITEM* pItemNext,
  253. MMC_COOKIE* pCookie);
  254. STDMETHOD(GetParentItem)(HSCOPEITEM item, HSCOPEITEM* pItemParent,
  255. MMC_COOKIE* pCookie);
  256. // IConsoleNameSpace2 method(s)
  257. STDMETHOD(Expand)(HSCOPEITEM hItem);
  258. STDMETHOD(AddExtension)(HSCOPEITEM hItem, LPCLSID lpclsid);
  259. private:
  260. enum EGetItem
  261. {
  262. egiParent = 1,
  263. egiChild = 2,
  264. egiNext = 3
  265. };
  266. HRESULT GetRelativeItem(EGetItem egi, HSCOPEITEM item, HSCOPEITEM* pItem,
  267. MMC_COOKIE* pCookie);
  268. ///////////////////////////////////////////////////////////////////////////////
  269. // IContextMenuCallback interface
  270. public:
  271. STDMETHOD(AddItem) ( CONTEXTMENUITEM* pItem );
  272. ///////////////////////////////////////////////////////////////////////////////
  273. // IContextMenuProvider interface
  274. public:
  275. STDMETHOD(EmptyMenuList) ();
  276. STDMETHOD(AddThirdPartyExtensionItems) (
  277. IDataObject* piDataObject );
  278. STDMETHOD(AddPrimaryExtensionItems) (
  279. IUnknown* piCallback,
  280. IDataObject* piDataObject );
  281. STDMETHOD(ShowContextMenu) (HWND hwndParent,
  282. LONG xPos,
  283. LONG yPos,
  284. LONG* plSelected);
  285. private:
  286. ContextMenuPtr m_spContextMenu;
  287. CContextMenu * GetContextMenu();
  288. ///////////////////////////////////////////////////////////////////////////////
  289. // IImageListPrivate interface
  290. public:
  291. STDMETHOD(ImageListSetIcon)(PLONG_PTR pIcon, LONG nLoc);
  292. STDMETHOD(ImageListSetStrip)(PLONG_PTR pBMapSm, PLONG_PTR pBMapLg,
  293. LONG nStartLoc, COLORREF cMask);
  294. STDMETHOD(MapRsltImage)(COMPONENTID id, int nSnapinIndex, int *pnConsoleIndex);
  295. STDMETHOD(UnmapRsltImage)(COMPONENTID id, int nConsoleIndex, int *pnSnapinIndex);
  296. ///////////////////////////////////////////////////////////////////////////////
  297. // IToobar interface
  298. ///////////////////////////////////////////////////////////////////////////////
  299. // Node Manager internal members
  300. private:
  301. void Construct();
  302. void Destruct();
  303. HRESULT CheckArgument(VARIANT* pArg);
  304. SC ScIsVirtualList(bool& bVirtual);
  305. public:
  306. HRESULT static GetSnapInAndNodeType(LPDATAOBJECT pDataObject,
  307. CSnapIn** ppSnapIn, GUID* pguidObjectType);
  308. IComponent* GetComponent() { return m_spComponent;}
  309. };
  310. #include <poppack.h>
  311. inline STDMETHODIMP CNodeInitObject::GetComponentID(COMPONENTID* lpComponentID)
  312. {
  313. MMC_TRY
  314. ASSERT(m_componentID != -1); // The component ID has not been set yet!!!
  315. ASSERT(lpComponentID);
  316. *lpComponentID = m_componentID;
  317. return S_OK;
  318. MMC_CATCH
  319. }
  320. inline STDMETHODIMP CNodeInitObject::SetComponentID(COMPONENTID id)
  321. {
  322. MMC_TRY
  323. /* for dynamic icon, we need to change this value temporarily
  324. if (m_componentID != -1)
  325. {
  326. ASSERT(FALSE); // ID already has been set!!!
  327. return E_UNEXPECTED;
  328. }
  329. ASSERT(id != -1);
  330. */
  331. m_componentID = id;
  332. return S_OK;
  333. MMC_CATCH
  334. }
  335. inline STDMETHODIMP CNodeInitObject::SetNode(HMTNODE hMTNode, HNODE hNode)
  336. {
  337. MMC_TRY
  338. m_pMTNode = CMTNode::FromHandle(hMTNode);
  339. m_pNode = CNode::FromHandle(hNode);
  340. return S_OK;
  341. MMC_CATCH
  342. }
  343. inline STDMETHODIMP CNodeInitObject::SetComponent(LPCOMPONENT lpComponent)
  344. {
  345. MMC_TRY
  346. if (lpComponent == NULL)
  347. {
  348. ASSERT(FALSE);
  349. return E_INVALIDARG;
  350. }
  351. m_spComponent = lpComponent;
  352. return S_OK;
  353. MMC_CATCH
  354. }
  355. inline STDMETHODIMP CNodeInitObject::SetUsedByExtension(BOOL bExtension)
  356. {
  357. MMC_TRY
  358. m_bExtension = bExtension;
  359. return S_OK;
  360. MMC_CATCH
  361. }
  362. inline STDMETHODIMP CNodeInitObject::IsUsedByExtension(void)
  363. {
  364. MMC_TRY
  365. return m_bExtension ? S_OK : S_FALSE;
  366. MMC_CATCH
  367. }
  368. inline SC CNodeInitObject::ScIsVirtualList(bool& bVirtual)
  369. {
  370. DECLARE_SC(sc, TEXT("CNodeInitObject::ScIsVirtualList"));
  371. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  372. if (sc)
  373. return sc;
  374. long lStyle = m_spListViewPrivate->GetListStyle();
  375. bVirtual = (lStyle & LVS_OWNERDATA);
  376. return sc;
  377. }
  378. inline STDMETHODIMP CNodeInitObject::GetMainWindow(HWND* phwnd)
  379. {
  380. MMC_TRY
  381. if (phwnd == NULL)
  382. return E_POINTER;
  383. *phwnd = GetMainWindow();
  384. ASSERT(*phwnd != NULL);
  385. return (*phwnd != NULL) ? S_OK : E_UNEXPECTED;
  386. MMC_CATCH
  387. }
  388. // Used for getting snapin name for debug info.
  389. inline void Debug_SetNodeInitSnapinName(CSnapInPtr pSnapIn, IFramePrivate* pIFrame)
  390. {
  391. #ifdef DBG
  392. CNodeInitObject* pNodeInitObj = dynamic_cast<CNodeInitObject*>(pIFrame);
  393. if ((pSnapIn != NULL) && (pNodeInitObj != NULL))
  394. {
  395. WTL::CString strSnapInName;
  396. SC sc = pSnapIn->ScGetSnapInName(strSnapInName);
  397. if (sc)
  398. return;
  399. if (!strSnapInName.IsEmpty())
  400. {
  401. pNodeInitObj->SetSnapinName(strSnapInName);
  402. CColumnData* pColumnData = dynamic_cast<CColumnData*>(pNodeInitObj);
  403. if (pColumnData)
  404. pColumnData->SetSnapinName(strSnapInName);
  405. }
  406. };
  407. #endif
  408. }
  409. #endif // _NODEINIT_H_