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.

1866 lines
50 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: nodeinit.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // NodeInit.cpp : Implementation of CNodeMgrApp and DLL registration.
  11. #include "stdafx.h"
  12. #include "menuitem.h" // MENUITEM_BASE_ID
  13. #include "scopimag.h"
  14. #include <bitmap.h>
  15. #include "NodeMgr.h"
  16. #include "amcmsgid.h"
  17. #include "scopndcb.h"
  18. #include "conframe.h"
  19. #include "conview.h"
  20. #include "constatbar.h"
  21. #include "util.h"
  22. #include "helpdoc.h"
  23. #ifdef _DEBUG
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. DEBUG_DECLARE_INSTANCE_COUNTER(CNodeInitObject);
  28. IScopeTreePtr CNodeInitObject::m_spScopeTree = NULL;
  29. // NTRAID#NTBUG9-461280-03-SEP-2002-jrowlett
  30. // delimit chm urls with "::" instead of "::/"
  31. #define TOPIC_DELIMITER _T("::")
  32. /////////////////////////////////////////////////////////////////////////////
  33. //
  34. STDMETHODIMP CNodeInitObject::InterfaceSupportsErrorInfo(REFIID riid)
  35. {
  36. if (riid == IID_IConsole)
  37. return S_OK;
  38. return S_FALSE;
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // IFramePrivate implementation
  42. CNodeInitObject::CNodeInitObject()
  43. {
  44. Construct();
  45. }
  46. CNodeInitObject::~CNodeInitObject()
  47. {
  48. DEBUG_DECREMENT_INSTANCE_COUNTER(CNodeInitObject);
  49. TRACE_DESTRUCTOR (CNodeInitObject);
  50. Destruct();
  51. }
  52. void CNodeInitObject::Construct()
  53. {
  54. DEBUG_INCREMENT_INSTANCE_COUNTER(CNodeInitObject);
  55. TRACE_CONSTRUCTOR (CNodeInitObject);
  56. m_pLVImage = NULL;
  57. m_pTVImage = NULL;
  58. m_pToolbar = NULL;
  59. m_pImageListPriv = NULL;
  60. m_componentID = -1;
  61. m_pMTNode = NULL;
  62. m_pNode = NULL;
  63. m_bExtension = FALSE;
  64. m_spComponent = NULL;
  65. m_spConsoleVerb = NULL;
  66. m_sortParams.bAscending = TRUE;
  67. m_sortParams.nCol = -1;
  68. m_sortParams.lpResultCompare = NULL;
  69. m_sortParams.lpResultCompareEx = NULL;
  70. m_sortParams.lpUserParam = NULL;
  71. // IContextMenuProvider attributes
  72. VERIFY(SUCCEEDED(EmptyMenuList()));
  73. }
  74. void CNodeInitObject::Destruct()
  75. {
  76. // Release all interfaces from the snap-in
  77. SAFE_RELEASE(m_pLVImage);
  78. SAFE_RELEASE(m_pTVImage);
  79. SAFE_RELEASE(m_pToolbar);
  80. SAFE_RELEASE(m_pImageListPriv);
  81. // IContextMenuProvider attributes
  82. VERIFY( SUCCEEDED(EmptyMenuList()) );
  83. }
  84. STDMETHODIMP CNodeInitObject::ResetSortParameters()
  85. {
  86. m_sortParams.nCol = -1;
  87. return (S_OK);
  88. }
  89. //+-------------------------------------------------------------------
  90. //
  91. // Member: CNodeInitObject::SetHeader
  92. //
  93. // Synopsis: This method is obsolete in MMC1.2
  94. //
  95. // Arguments:
  96. //
  97. // Note: Should be called by IComponent object.
  98. //
  99. // Returns: HRESULT
  100. //
  101. //--------------------------------------------------------------------
  102. STDMETHODIMP CNodeInitObject::SetHeader(IHeaderCtrl* pHeader)
  103. {
  104. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::SetHeader"));
  105. return sc.ToHr();
  106. }
  107. //+-------------------------------------------------------------------
  108. //
  109. // Member: CNodeInitObject::SetToolbar
  110. //
  111. // Synopsis: The toolbar interface used by IComponent.
  112. //
  113. // Arguments: [pToolbar]
  114. //
  115. // Note: Should be called by IComponent object.
  116. //
  117. // Returns: HRESULT
  118. //
  119. //--------------------------------------------------------------------
  120. STDMETHODIMP CNodeInitObject::SetToolbar(IToolbar* pToolbar)
  121. {
  122. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::SetToolbar"));
  123. if (GetComponent() == NULL)
  124. {
  125. sc = E_UNEXPECTED;
  126. TraceSnapinError(_T("This method is valid for IConsole of IComponent"), sc);
  127. return sc.ToHr();
  128. }
  129. // Release the OLD one
  130. SAFE_RELEASE(m_pToolbar);
  131. if (pToolbar != NULL)
  132. {
  133. m_pToolbar = pToolbar;
  134. m_pToolbar->AddRef();
  135. }
  136. return sc.ToHr();
  137. }
  138. //+-------------------------------------------------------------------
  139. //
  140. // Member: CNodeInitObject::QueryScopeImageList
  141. //
  142. // Synopsis: Get scope-pane's image list.
  143. //
  144. // Arguments:
  145. //
  146. // Returns: HRESULT
  147. //
  148. //--------------------------------------------------------------------
  149. STDMETHODIMP CNodeInitObject::QueryScopeImageList(LPIMAGELIST* ppImageList)
  150. {
  151. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::QueryScopeImageList"));
  152. if (ppImageList == NULL)
  153. {
  154. sc = E_INVALIDARG;
  155. TraceSnapinError(_T("NULL LPIMAGELIST ptr"), sc);
  156. return sc.ToHr();
  157. }
  158. sc = ScCheckPointers(m_pImageListPriv, E_FAIL);
  159. if (sc)
  160. return sc.ToHr();
  161. *ppImageList = (IImageList*)m_pImageListPriv;
  162. m_pImageListPriv->AddRef();
  163. return sc.ToHr();
  164. }
  165. //+-------------------------------------------------------------------
  166. //
  167. // Member: CNodeInitObject::CreateScopeImageList
  168. //
  169. // Synopsis: Create the ScopeImage list.
  170. //
  171. // Arguments:
  172. //
  173. // Returns: HRESULT
  174. //
  175. //--------------------------------------------------------------------
  176. STDMETHODIMP CNodeInitObject::CreateScopeImageList(REFCLSID refClsidSnapIn)
  177. {
  178. DECLARE_SC(sc, _T("CNodeInitObject::CreateScopeImageList"));
  179. if (m_pImageListPriv != NULL)
  180. return sc.ToHr(); // Already exists.
  181. try
  182. {
  183. CScopeTree* pScopeTree =
  184. dynamic_cast<CScopeTree*>((IScopeTree*)m_spScopeTree);
  185. sc = ScCheckPointers(pScopeTree, E_UNEXPECTED);
  186. if (sc)
  187. return sc.ToHr();
  188. CSnapInImageList *psiil =
  189. new CSnapInImageList(pScopeTree->GetImageCache(),
  190. refClsidSnapIn);
  191. m_pImageListPriv = (LPIMAGELISTPRIVATE)psiil;
  192. }
  193. catch( std::bad_alloc )
  194. {
  195. sc = E_OUTOFMEMORY;
  196. }
  197. return sc.ToHr();
  198. }
  199. //+-------------------------------------------------------------------
  200. //
  201. // Member: CNodeInitObject::QueryResultImageList
  202. //
  203. // Synopsis:
  204. //
  205. // Arguments:
  206. //
  207. // Returns: SC
  208. //
  209. //--------------------------------------------------------------------
  210. STDMETHODIMP CNodeInitObject::QueryResultImageList(LPIMAGELIST *ppImageList)
  211. {
  212. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::QueryResultImageList"));
  213. LPCONSOLE pConsole = (LPCONSOLE)this;
  214. sc = ScCheckPointers(pConsole, E_UNEXPECTED);
  215. if (sc)
  216. return sc.ToHr();
  217. sc = pConsole->QueryInterface(IID_IImageList, (void**)ppImageList);
  218. return sc.ToHr();
  219. }
  220. //+-------------------------------------------------------------------
  221. //
  222. // Member: CNodeInitObject::UpdateAllViews
  223. //
  224. // Synopsis: Update all the views.
  225. //
  226. // Arguments: [lpDataObject] -
  227. // [data]
  228. // [hint]
  229. //
  230. // Returns: HRESULT
  231. //
  232. //--------------------------------------------------------------------
  233. STDMETHODIMP CNodeInitObject::UpdateAllViews(LPDATAOBJECT lpDataObject,
  234. LPARAM data, LONG_PTR hint)
  235. {
  236. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::UpdateAllViews"));
  237. COMPONENTID id;
  238. GetComponentID(&id);
  239. sc = ScCheckPointers(m_pMTNode, E_UNEXPECTED);
  240. if (sc)
  241. return sc.ToHr();
  242. CMTSnapInNode* pMTSINode = m_pMTNode->GetStaticParent();
  243. sc = ScCheckPointers(pMTSINode, E_UNEXPECTED);
  244. if (sc)
  245. return sc.ToHr();
  246. CNodeList& nodes = pMTSINode->GetNodeList();
  247. POSITION pos = nodes.GetHeadPosition();
  248. while (pos)
  249. {
  250. CSnapInNode* pSINode = dynamic_cast<CSnapInNode*>(nodes.GetNext(pos));
  251. sc = ScCheckPointers(pSINode, E_UNEXPECTED);
  252. if (sc)
  253. return sc.ToHr();
  254. CComponent* pCC = pSINode->GetComponent(id);
  255. sc = ScCheckPointers(pCC, E_UNEXPECTED);
  256. if (sc)
  257. {
  258. sc.TraceAndClear();
  259. continue;
  260. }
  261. pCC->Notify(lpDataObject, MMCN_VIEW_CHANGE, data, hint);
  262. }
  263. return sc.ToHr();
  264. }
  265. //+-------------------------------------------------------------------
  266. //
  267. // Member: CNodeInitObject::InsertColumn
  268. //
  269. // Synopsis: Insert a column is ListView.
  270. //
  271. // Arguments: [nCol] - Column index.
  272. // [lpszTitle] - Name of the column.
  273. // [nFormat] - Column style.
  274. // [nWidth] - Column width.
  275. //
  276. // Returns: HRESULT
  277. //
  278. //--------------------------------------------------------------------
  279. STDMETHODIMP CNodeInitObject::InsertColumn(int nCol, LPCWSTR lpszTitle, int nFormat, int nWidth)
  280. {
  281. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IHeaderCtrl2::InsertColumn"));
  282. if (nCol < 0)
  283. {
  284. sc = E_INVALIDARG;
  285. TraceSnapinError(_T("Column index is negative"), sc);
  286. return sc.ToHr();
  287. }
  288. if (!lpszTitle || !*lpszTitle)
  289. {
  290. sc = E_INVALIDARG;
  291. TraceSnapinError(_T("Column name is NULL"), sc);
  292. return sc.ToHr();
  293. }
  294. if (nCol == 0 && nFormat != LVCFMT_LEFT)
  295. {
  296. sc = E_INVALIDARG;
  297. TraceSnapinError(_T("Column zero must be LVCFMT_LEFT"), sc);
  298. return sc.ToHr();
  299. }
  300. if (nFormat != LVCFMT_LEFT && nFormat != LVCFMT_CENTER && nFormat != LVCFMT_RIGHT)
  301. {
  302. sc = E_INVALIDARG;
  303. TraceSnapinError(_T("Unknown format for the Column"), sc);
  304. return sc.ToHr();
  305. }
  306. // Cannot hide column 0.
  307. if ( (0 == nCol) && (HIDE_COLUMN == nWidth))
  308. nWidth = AUTO_WIDTH;
  309. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  310. if (sc)
  311. return sc.ToHr();
  312. // Insert the column into the listview
  313. sc = m_spListViewPrivate->InsertColumn(nCol, lpszTitle, nFormat, nWidth);
  314. return sc.ToHr();
  315. }
  316. //+-------------------------------------------------------------------
  317. //
  318. // Member: CNodeInitObject::DeleteColumn
  319. //
  320. // Synopsis: Delete a column
  321. //
  322. // Arguments: [nCol] - column index.
  323. //
  324. // Returns: HRESULT
  325. //
  326. //--------------------------------------------------------------------
  327. STDMETHODIMP CNodeInitObject::DeleteColumn(int nCol)
  328. {
  329. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IHeaderCtrl2::DeleteColumn"));
  330. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  331. if (sc)
  332. return sc.ToHr();
  333. sc = m_spListViewPrivate->DeleteColumn(nCol);
  334. return sc.ToHr();
  335. }
  336. //+-------------------------------------------------------------------
  337. //
  338. // Member: CNodeInitObject::SetColumnText
  339. //
  340. // Synopsis: Modify column text.
  341. //
  342. // Arguments: [title] - new name.
  343. //
  344. // Returns: HRESULT
  345. //
  346. //--------------------------------------------------------------------
  347. STDMETHODIMP CNodeInitObject::SetColumnText(int nCol, LPCWSTR title)
  348. {
  349. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IHeaderCtrl2::SetColumnText"));
  350. if (!title || !*title)
  351. {
  352. sc = E_INVALIDARG;
  353. TraceSnapinError(_T("NULL column text"), sc);
  354. return sc.ToHr();
  355. }
  356. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  357. if (sc)
  358. return sc.ToHr();
  359. sc = m_spListViewPrivate->SetColumn(nCol, title, MMCLV_NOPARAM, MMCLV_NOPARAM);
  360. return sc.ToHr();
  361. }
  362. //+-------------------------------------------------------------------
  363. //
  364. // Member: CNodeInitObject::GetColumnText
  365. //
  366. // Synopsis: Get the name of a column.
  367. //
  368. // Arguments: [nCol] - Index of Column whose name is sought.
  369. // [pText] - Name.
  370. //
  371. // Returns: HRESULT
  372. //
  373. //--------------------------------------------------------------------
  374. STDMETHODIMP CNodeInitObject::GetColumnText(int nCol, LPWSTR* pText)
  375. {
  376. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IHeaderCtrl2::GetColumnText"));
  377. if (pText == NULL)
  378. {
  379. sc = E_INVALIDARG;
  380. TraceSnapinError(_T("NULL text ptr"), sc);
  381. return sc.ToHr();
  382. }
  383. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  384. if (sc)
  385. return sc.ToHr();
  386. sc = m_spListViewPrivate->GetColumn(nCol, pText, MMCLV_NOPTR, MMCLV_NOPTR);
  387. return sc.ToHr();
  388. }
  389. //+-------------------------------------------------------------------
  390. //
  391. // Member: CNodeInitObject::SetColumnWidth
  392. //
  393. // Synopsis: Change width of a column
  394. //
  395. // Arguments: [nCol] - Column index.
  396. // [nWidth] - new width.
  397. //
  398. // Returns: SC
  399. //
  400. //--------------------------------------------------------------------
  401. STDMETHODIMP CNodeInitObject::SetColumnWidth(int nCol, int nWidth)
  402. {
  403. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IHeaderCtrl2::SetColumnWidth"));
  404. if (nCol < 0)
  405. {
  406. sc = E_INVALIDARG;
  407. TraceSnapinError(_T("Negative column index"), sc);
  408. return sc.ToHr();
  409. }
  410. // job on parameter checking nWidth
  411. if (nWidth < 0 && ( (nWidth != MMCLV_AUTO) && (nWidth != HIDE_COLUMN) ) )
  412. {
  413. sc = E_INVALIDARG;
  414. TraceSnapinError(_T("Invalid column width"), sc);
  415. return sc.ToHr();
  416. }
  417. // Cannot hide column 0.
  418. if ( (0 == nCol) && (HIDE_COLUMN == nWidth))
  419. nWidth = AUTO_WIDTH;
  420. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  421. if (sc)
  422. return sc.ToHr();
  423. sc = m_spListViewPrivate->SetColumn(nCol, MMCLV_NOPTR, MMCLV_NOPARAM, nWidth);
  424. return sc.ToHr();
  425. }
  426. //+-------------------------------------------------------------------
  427. //
  428. // Member: CNodeInitObject::GetColumnWidth
  429. //
  430. // Synopsis: Get width of a column.
  431. //
  432. // Arguments: [nCol] - col index.
  433. // [pWidth] - width.
  434. //
  435. // Returns: HRESULT
  436. //
  437. //--------------------------------------------------------------------
  438. STDMETHODIMP CNodeInitObject::GetColumnWidth(int nCol, int* pWidth)
  439. {
  440. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IHeaderCtrl2::GetColumnWidth"));
  441. if (nCol < 0 )
  442. {
  443. sc = E_INVALIDARG;
  444. TraceSnapinError(_T("Negative column index"), sc);
  445. return sc.ToHr();
  446. }
  447. if (pWidth == NULL)
  448. {
  449. sc = E_POINTER;
  450. TraceSnapinError(_T("NULL width pointer"), sc);
  451. return sc.ToHr();
  452. }
  453. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  454. if (sc)
  455. return sc.ToHr();
  456. sc = m_spListViewPrivate->GetColumn(nCol, MMCLV_NOPTR, MMCLV_NOPTR, pWidth);
  457. return sc.ToHr();
  458. }
  459. //+-------------------------------------------------------------------
  460. //
  461. // Member: CNodeInitObject::GetColumnCount
  462. //
  463. // Synopsis: Returns the number of columns in listview.
  464. //
  465. // Arguments: [pnCol] - [out param], number of cols.
  466. //
  467. // Returns: HRESULT
  468. //
  469. //--------------------------------------------------------------------
  470. STDMETHODIMP CNodeInitObject::GetColumnCount (INT* pnCol)
  471. {
  472. DECLARE_SC(sc, _T("CNodeInitObject::GetColumnCount"));
  473. sc = ScCheckPointers(pnCol);
  474. if (sc)
  475. return sc.ToHr();
  476. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  477. if (sc)
  478. return sc.ToHr();
  479. sc = m_spListViewPrivate->GetColumnCount(pnCol);
  480. if (sc)
  481. return sc.ToHr();
  482. return (sc.ToHr());
  483. }
  484. //+-------------------------------------------------------------------
  485. //
  486. // Member: CNodeInitObject::GetColumnInfoList
  487. //
  488. // Synopsis: Get the CColumnInfoList for current list-view headers.
  489. //
  490. // Arguments: [pColumnsList] - [out param], ptr to CColumnInfoList.
  491. //
  492. // Returns: SC
  493. //
  494. //--------------------------------------------------------------------
  495. STDMETHODIMP CNodeInitObject::GetColumnInfoList (CColumnInfoList *pColumnsList)
  496. {
  497. DECLARE_SC(sc, _T("CNodeInitObject::GetColumnInfoList"));
  498. sc = ScCheckPointers(pColumnsList);
  499. if (sc)
  500. return sc.ToHr();
  501. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  502. if (sc)
  503. return sc.ToHr();
  504. sc = m_spListViewPrivate->GetColumnInfoList(pColumnsList);
  505. if (sc)
  506. return sc.ToHr();
  507. return (sc.ToHr());
  508. }
  509. //+-------------------------------------------------------------------
  510. //
  511. // Member: CNodeInitObject::ModifyColumns
  512. //
  513. // Synopsis: Modify the columns with given data.
  514. //
  515. // Arguments: [columnsList] -
  516. //
  517. // Returns: SC
  518. //
  519. //--------------------------------------------------------------------
  520. STDMETHODIMP CNodeInitObject::ModifyColumns (const CColumnInfoList& columnsList)
  521. {
  522. DECLARE_SC(sc, _T("CNodeInitObject::ModifyColumns"));
  523. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  524. if (sc)
  525. return sc.ToHr();
  526. sc = m_spListViewPrivate->ModifyColumns(columnsList);
  527. if (sc)
  528. return sc.ToHr();
  529. return (sc.ToHr());
  530. }
  531. //+-------------------------------------------------------------------
  532. //
  533. // Member: CNodeInitObject::GetDefaultColumnInfoList
  534. //
  535. // Synopsis: Get the original column settings supplied by the snapin.
  536. //
  537. // Arguments: [columnsList] - [out] the column settings
  538. //
  539. // Returns: HRESULT
  540. //
  541. //--------------------------------------------------------------------
  542. STDMETHODIMP CNodeInitObject::GetDefaultColumnInfoList (CColumnInfoList& columnsList)
  543. {
  544. DECLARE_SC(sc, _T("CNodeInitObject::RestoreDefaultColumnSettings"));
  545. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  546. if (sc)
  547. return sc.ToHr();
  548. sc = m_spListViewPrivate->GetDefaultColumnInfoList(columnsList);
  549. if (sc)
  550. return sc.ToHr();
  551. return (sc.ToHr());
  552. }
  553. //+-------------------------------------------------------------------
  554. //
  555. // Member: CNodeInitObject::ImageListSetIcon
  556. //
  557. // Synopsis: Set an icon in imagelist.
  558. //
  559. // Arguments: [pIcon] - HICON ptr.
  560. // [nLoc] - index of this item.
  561. //
  562. // Returns: HRESULT
  563. //
  564. //--------------------------------------------------------------------
  565. STDMETHODIMP CNodeInitObject::ImageListSetIcon(PLONG_PTR pIcon, LONG nLoc)
  566. {
  567. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IImageList::ImageListSetIcon"));
  568. if (!pIcon)
  569. {
  570. sc = E_INVALIDARG;
  571. TraceSnapinError(_T("NULL pIcon ptr"), sc);
  572. return sc.ToHr();
  573. }
  574. if(nLoc < 0)
  575. {
  576. sc = E_INVALIDARG;
  577. TraceSnapinError(_T("Negative index"), sc);
  578. return sc.ToHr();
  579. }
  580. COMPONENTID id;
  581. GetComponentID(&id);
  582. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  583. if (sc)
  584. return sc.ToHr();
  585. sc = m_spListViewPrivate->SetIcon(id, reinterpret_cast<HICON>(pIcon), nLoc);
  586. return sc.ToHr();
  587. }
  588. //+-------------------------------------------------------------------
  589. //
  590. // Member: CNodeInitObject::ImageListSetStrip
  591. //
  592. // Synopsis: Add strip of icons to image list.
  593. //
  594. // Arguments: [pBMapSm] - Ptr to HBITMAP of 16x16.
  595. // [pBMapLg] - Ptr to HBITMAP of 32x32.
  596. // [nStartLoc] - Start index.
  597. // [cMask] - mask.
  598. //
  599. // Returns: HRESULT
  600. //
  601. //--------------------------------------------------------------------
  602. STDMETHODIMP CNodeInitObject::ImageListSetStrip (
  603. PLONG_PTR pBMapSm,
  604. PLONG_PTR pBMapLg,
  605. LONG nStartLoc,
  606. COLORREF cMask)
  607. {
  608. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IImageList::ImageListSetStrip"));
  609. HBITMAP hbmSmall = (HBITMAP) pBMapSm;
  610. HBITMAP hbmLarge = (HBITMAP) pBMapLg;
  611. /*
  612. * valid start index?
  613. */
  614. if (nStartLoc < 0)
  615. {
  616. sc = E_INVALIDARG;
  617. TraceSnapinError (_T("Negative start index"), sc);
  618. return (sc.ToHr());
  619. }
  620. /*
  621. * valid bitmaps?
  622. */
  623. sc = ScCheckPointers (hbmSmall, hbmLarge);
  624. if (sc)
  625. {
  626. TraceSnapinError (_T("Invalid bitmap"), sc);
  627. return (sc.ToHr());
  628. }
  629. BITMAP bmSmall;
  630. if (!GetObject (hbmSmall, sizeof(BITMAP), &bmSmall))
  631. {
  632. sc.FromLastError();
  633. TraceSnapinError (_T("Invalid Small bitmap object"), sc);
  634. return (sc.ToHr());
  635. }
  636. BITMAP bmLarge;
  637. if (!GetObject (hbmLarge, sizeof(BITMAP), &bmLarge))
  638. {
  639. sc.FromLastError();
  640. TraceSnapinError (_T("Invalid Large bitmap object"), sc);
  641. return (sc.ToHr());
  642. }
  643. /*
  644. * are the small and large bitmaps of the integral dimensions,
  645. * and do they have the same number of images?
  646. */
  647. if ( (bmSmall.bmHeight != 16) || (bmLarge.bmHeight != 32) ||
  648. (bmSmall.bmWidth % 16) || (bmLarge.bmWidth % 32) ||
  649. ((bmSmall.bmWidth / 16) != (bmLarge.bmWidth / 32)))
  650. {
  651. sc = E_INVALIDARG;
  652. TraceSnapinError (_T("Invalid Bitmap size"), sc);
  653. return (sc.ToHr());
  654. }
  655. COMPONENTID id;
  656. GetComponentID(&id);
  657. /*
  658. * m_spListViewPrivate == NULL is unexpected, however because we send
  659. * MMCN_ADD_IMAGES when the result pane is an OCX (see CNode::OnSelect),
  660. * this function often gets called when m_spListViewPrivate == NULL.
  661. * Tracing this failure would be too noisy, since most OCX-based snap-ins
  662. * would trigger it, so we'll return E_UNEXPECTED here without tracing.
  663. * This is equivalent to MMC 1.2 behavior.
  664. */
  665. if (m_spListViewPrivate == NULL)
  666. return (E_UNEXPECTED);
  667. /*
  668. * add them to the imagelist
  669. */
  670. sc = m_spListViewPrivate->SetImageStrip (id, hbmSmall, hbmLarge, nStartLoc, cMask);
  671. return sc.ToHr();
  672. }
  673. //+-------------------------------------------------------------------
  674. //
  675. // Member: CNodeInitObject::MapRsltImage
  676. //
  677. // Synopsis:
  678. //
  679. // Arguments:
  680. //
  681. // Returns: HRESULT
  682. //
  683. //--------------------------------------------------------------------
  684. STDMETHODIMP CNodeInitObject::MapRsltImage(COMPONENTID id, int nSnapinIndex, int *pnConsoleIndex)
  685. {
  686. DECLARE_SC(sc, _T("CNodeInitObject::MapRsltImage"));
  687. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  688. if (sc)
  689. return sc.ToHr();
  690. // Ret val can be E_, no need to check.
  691. sc = m_spListViewPrivate->MapImage(id, nSnapinIndex, pnConsoleIndex);
  692. HRESULT hr = sc.ToHr();
  693. sc.Clear();
  694. return hr;
  695. }
  696. //+-------------------------------------------------------------------
  697. //
  698. // Member: CNodeInitObject::UnmapRsltImage
  699. //
  700. // Synopsis:
  701. //
  702. // Arguments:
  703. //
  704. // Returns: HRESULT
  705. //
  706. //--------------------------------------------------------------------
  707. STDMETHODIMP CNodeInitObject::UnmapRsltImage(COMPONENTID id, int nConsoleIndex, int *pnSnapinIndex)
  708. {
  709. DECLARE_SC(sc, _T("CNodeInitObject::UnmapRsltImage"));
  710. return (sc = E_NOTIMPL).ToHr(); // not needed now
  711. }
  712. //+-------------------------------------------------------------------
  713. //
  714. // Member: CNodeInitObject::SetChangeTimeOut
  715. //
  716. // Synopsis: Change timeout interval for filter attributes.
  717. //
  718. // Arguments: [uTimeout] - timeout
  719. //
  720. // Returns: HRESULT
  721. //
  722. //--------------------------------------------------------------------
  723. STDMETHODIMP CNodeInitObject::SetChangeTimeOut(unsigned long uTimeout)
  724. {
  725. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IHeaderCtrl2::SetChangeTimeOut"));
  726. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  727. if (sc)
  728. return sc.ToHr();
  729. sc = m_spListViewPrivate->SetChangeTimeOut(uTimeout);
  730. return sc.ToHr();
  731. }
  732. //+-------------------------------------------------------------------
  733. //
  734. // Member: CNodeInitObject::SetColumnFilter
  735. //
  736. // Synopsis: Set filter for a column.
  737. //
  738. // Arguments: [nColumn] - Column index.
  739. // [dwType] - Filter type.
  740. // [pFilterData] - Filter data.
  741. //
  742. // Returns: HRESULT
  743. //
  744. //--------------------------------------------------------------------
  745. STDMETHODIMP CNodeInitObject::SetColumnFilter(UINT nColumn, DWORD dwType, MMC_FILTERDATA* pFilterData)
  746. {
  747. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IHeaderCtrl2::SetColumnFilter"));
  748. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  749. if (sc)
  750. return sc.ToHr();
  751. sc = m_spListViewPrivate->SetColumnFilter(nColumn, dwType, pFilterData);
  752. return sc.ToHr();
  753. }
  754. //+-------------------------------------------------------------------
  755. //
  756. // Member: CNodeInitObject::GetColumnFilter
  757. //
  758. // Synopsis: Get filter data.
  759. //
  760. // Arguments: [nColumn] - Column index.
  761. // [pdwType] - Filter type.
  762. // [pFilterData] - Filter data.
  763. //
  764. // Returns: HRESULT
  765. //
  766. //--------------------------------------------------------------------
  767. STDMETHODIMP CNodeInitObject::GetColumnFilter(UINT nColumn, LPDWORD pdwType, MMC_FILTERDATA* pFilterData)
  768. {
  769. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IHeaderCtrl2::GetColumnFilter"));
  770. if (pdwType == NULL)
  771. {
  772. sc = E_POINTER;
  773. TraceSnapinError(_T("NULL filtertype ptr"), sc);
  774. return sc.ToHr();
  775. }
  776. if (NULL == pFilterData)
  777. {
  778. sc = E_POINTER;
  779. TraceSnapinError(_T("NULL FilterData ptr"), sc);
  780. return sc.ToHr();
  781. }
  782. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  783. if (sc)
  784. return sc.ToHr();
  785. sc = m_spListViewPrivate->GetColumnFilter(nColumn, pdwType, pFilterData);
  786. return sc.ToHr();
  787. }
  788. //+-------------------------------------------------------------------
  789. //
  790. // Member: CNodeInitObject::ShowTopic
  791. //
  792. // Synopsis: Display specified help topic.
  793. //
  794. // Arguments: [pszHelpTopic]
  795. //
  796. // Returns: HRESULT
  797. //
  798. //--------------------------------------------------------------------
  799. STDMETHODIMP CNodeInitObject::ShowTopic(LPOLESTR pszHelpTopic)
  800. {
  801. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IDisplayHelp::ShowTopic"));
  802. // Get the AMCView window
  803. CConsoleView* pConsoleView = GetConsoleView();
  804. sc = ScCheckPointers(pConsoleView, E_UNEXPECTED);
  805. if (sc)
  806. return sc.ToHr();
  807. /*
  808. * first MUI localize the help topic if possible so it matches what we have in the collection
  809. *
  810. */
  811. //NOTE: WTL::CString may throw exceptions; the following code matches exception handling behavior of CHelpDoc,
  812. //which is to just let exceptions bubble up
  813. USES_CONVERSION;
  814. WTL::CString strPathTopic = W2T(pszHelpTopic);
  815. //the topic will be passed in formed like: "WINDOWS\help\sys_srv.chm::/sys_srv_overview.htm"
  816. //parse off the path and topic, which is delimited by "::"
  817. int iDelim = strPathTopic.Find(TOPIC_DELIMITER);
  818. if (iDelim == -1)
  819. {
  820. //invalid format
  821. sc = E_INVALIDARG;
  822. TraceSnapinError(_T("ShowTopic - Malformed help topic"), sc);
  823. return sc.ToHr();
  824. }
  825. //pass the path to CHelpDoc::ScRedirectHelpFile, which will localize it if possible
  826. WTL::CString strPath = strPathTopic.Left(iDelim);
  827. WTL::CString strTopic = strPathTopic.Mid(iDelim + sizeof(TOPIC_DELIMITER)/sizeof(TOPIC_DELIMITER[0]) - 1);
  828. //langID is an out param; we aren't concerned with the results of it here
  829. LANGID langID;
  830. //ScRedirectHelpFile will convert strPath to localized path if possible
  831. sc = CHelpDoc::ScRedirectHelpFile(strPath, langID);
  832. if (sc)
  833. return sc.ToHr();
  834. //build the help topic back up
  835. strPathTopic.Format(_T("%s") TOPIC_DELIMITER _T("%s"),strPath, strTopic);
  836. sc = pConsoleView->ScShowSnapinHelpTopic ( (LPCTSTR)strPathTopic);
  837. return sc.ToHr();
  838. }
  839. //+-------------------------------------------------------------------
  840. //
  841. // Member: CNodeInitObject::AddExtension
  842. //
  843. // Synopsis: Add a dynamic extension snapin to given HSCOPEITEM.
  844. //
  845. // Arguments: [hItem] -
  846. // [lpclsid] - CLSID of snapin to be added.
  847. //
  848. // Returns: HRESULT
  849. //
  850. //--------------------------------------------------------------------
  851. STDMETHODIMP CNodeInitObject::AddExtension(HSCOPEITEM hItem, LPCLSID lpclsid)
  852. {
  853. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsoleNameSpace2::AddExtension"));
  854. COMPONENTID nID;
  855. GetComponentID(&nID);
  856. if (nID == -1)
  857. {
  858. sc = E_UNEXPECTED;
  859. return sc.ToHr();
  860. }
  861. if (lpclsid == NULL)
  862. {
  863. sc = E_POINTER;
  864. TraceSnapinError(_T("NULL LPCLSID ptr"), sc);
  865. return sc.ToHr();
  866. }
  867. CMTNode *pMTNode = CMTNode::FromScopeItem (hItem);
  868. if (pMTNode == NULL)
  869. {
  870. sc = E_INVALIDARG;
  871. TraceSnapinError(_T("Invalid hItem"), sc);
  872. return sc.ToHr();
  873. }
  874. // Can not add extensions to other components' nodes
  875. // Do we need to protect TV owned nodes that do not represent this snapin?
  876. if (pMTNode->GetOwnerID() != nID && pMTNode->GetOwnerID() != TVOWNED_MAGICWORD)
  877. {
  878. sc = E_INVALIDARG;
  879. return sc.ToHr();
  880. }
  881. sc = pMTNode->AddExtension(lpclsid);
  882. return sc.ToHr();
  883. }
  884. ///////////////////////////////////////////////////////////////////////////////
  885. // Private methods
  886. HRESULT CNodeInitObject::CheckArgument(VARIANT* pArg)
  887. {
  888. if (pArg == NULL)
  889. return E_POINTER;
  890. // VT_NULL is acceptable
  891. if (pArg->vt == VT_NULL)
  892. return S_OK;
  893. // VT_UNKNOWN with a valid pointer is acceptable
  894. if (pArg->punkVal != NULL)
  895. {
  896. if (pArg->vt == VT_UNKNOWN)
  897. return S_OK;
  898. else
  899. return E_INVALIDARG;
  900. }
  901. else
  902. {
  903. return E_POINTER;
  904. }
  905. // any other VT type is unacceptable
  906. return E_INVALIDARG;
  907. }
  908. ///////////////////////////////////////////////////////////////////////////////
  909. //
  910. //
  911. //
  912. //
  913. ///////////////////////////////////////////////////////////////////////////////
  914. STDMETHODIMP CNodeInitObject::QueryScopeTree(IScopeTree** ppScopeTree)
  915. {
  916. ASSERT(ppScopeTree != NULL);
  917. if (ppScopeTree == NULL)
  918. return E_POINTER;
  919. ASSERT(m_spScopeTree != NULL);
  920. if (m_spScopeTree == NULL)
  921. return E_UNEXPECTED;
  922. *ppScopeTree = m_spScopeTree;
  923. (*ppScopeTree)->AddRef();
  924. return S_OK;
  925. }
  926. STDMETHODIMP CNodeInitObject::SetScopeTree(IScopeTree* pScopeTree)
  927. {
  928. m_spScopeTree = pScopeTree;
  929. return S_OK;
  930. }
  931. HRESULT CNodeInitObject::GetSnapInAndNodeType(LPDATAOBJECT pDataObject,
  932. CSnapIn** ppSnapIn, GUID* pguidObjectType)
  933. {
  934. ASSERT(pDataObject != NULL);
  935. ASSERT(ppSnapIn != NULL);
  936. ASSERT(pguidObjectType != NULL);
  937. CLSID clsidSnapin;
  938. HRESULT hr = ExtractSnapInCLSID(pDataObject, &clsidSnapin);
  939. if (FAILED(hr))
  940. return hr;
  941. CSnapIn* pSnapIn = NULL;
  942. SC sc = theApp.GetSnapInsCache()->ScGetSnapIn(clsidSnapin, &pSnapIn);
  943. if (sc)
  944. return sc.ToHr();
  945. // else
  946. ASSERT(pSnapIn != NULL);
  947. *ppSnapIn = pSnapIn;
  948. hr = ExtractObjectTypeGUID(pDataObject, pguidObjectType);
  949. return hr;
  950. }
  951. //+-------------------------------------------------------------------
  952. //
  953. // Member: CNodeInitObject::SelectScopeItem
  954. //
  955. // Synopsis: Select given scope-item.
  956. //
  957. // Arguments: [hScopeItem]
  958. //
  959. // Returns: HRESULT
  960. //
  961. //--------------------------------------------------------------------
  962. STDMETHODIMP CNodeInitObject::SelectScopeItem(HSCOPEITEM hScopeItem)
  963. {
  964. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::SelectScopeItem"));
  965. CViewData* pVD = (NULL == m_pNode ) ? NULL : m_pNode->GetViewData();
  966. CMTNode* pMTNode = CMTNode::FromScopeItem (hScopeItem);
  967. sc = ScCheckPointers(pMTNode);
  968. if (sc)
  969. {
  970. //bad handle passed in
  971. return sc.ToHr();
  972. }
  973. MTNODEID id = pMTNode->GetID();
  974. // If the currently selected node is same as the node being
  975. // asked to be selected, there is high probability that the
  976. // snapin is trying to change the view.
  977. // So set the viewchanging flag.
  978. CNode* pSelNode = (NULL == pVD) ? NULL : pVD->GetSelectedNode();
  979. CMTNode* pSelMTNode = (NULL == pSelNode) ? NULL : pSelNode->GetMTNode();
  980. if (pVD && pSelMTNode && (pSelMTNode == pMTNode) )
  981. {
  982. pVD->SetSnapinChangingView();
  983. }
  984. // Get the AMCView window
  985. CConsoleView* pConsoleView = GetConsoleView();
  986. sc = ScCheckPointers(pConsoleView, E_UNEXPECTED);
  987. if (sc)
  988. return sc.ToHr();
  989. CConsoleView::ViewPane ePane = pConsoleView->GetFocusedPane ();
  990. sc = pConsoleView->ScSelectNode (id);
  991. if (sc)
  992. return sc.ToHr();
  993. // ePane == ePane_None means active view is unknown
  994. if (ePane != CConsoleView::ePane_None)
  995. pConsoleView->ScSetFocusToPane (ePane);
  996. // Always reset the view changing flag.
  997. if (pVD)
  998. {
  999. pVD->ResetSnapinChangingView();
  1000. }
  1001. return sc.ToHr();
  1002. }
  1003. //+-------------------------------------------------------------------
  1004. //
  1005. // Member: CNodeInitObject::QueryConsoleVerb
  1006. //
  1007. // Synopsis: Get the IConsoleVerb for setting standard verbs.
  1008. //
  1009. // Arguments: [ppConsoleVerb]
  1010. //
  1011. // Returns: HRESULT
  1012. //
  1013. //--------------------------------------------------------------------
  1014. STDMETHODIMP CNodeInitObject::QueryConsoleVerb(LPCONSOLEVERB* ppConsoleVerb)
  1015. {
  1016. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::QueryConsoleVerb"));
  1017. if (ppConsoleVerb == NULL)
  1018. {
  1019. sc = E_POINTER;
  1020. TraceSnapinError(_T("NULL LPCONSOLEVERB ptr"), sc);
  1021. return sc.ToHr();
  1022. }
  1023. if (m_pNode == NULL)
  1024. {
  1025. sc = E_FAIL;
  1026. TraceSnapinError(_T("You can query console verb only from the IConsole associated with IComponents"), sc);
  1027. return sc.ToHr();
  1028. }
  1029. if (m_spConsoleVerb == NULL)
  1030. {
  1031. // Create new CConsoleVerbImpl.
  1032. CComObject<CConsoleVerbImpl>* pVerb;
  1033. sc = CComObject<CConsoleVerbImpl>::CreateInstance(&pVerb);
  1034. if (sc)
  1035. return sc.ToHr();
  1036. if (NULL == pVerb)
  1037. {
  1038. sc = E_OUTOFMEMORY;
  1039. return sc.ToHr();
  1040. }
  1041. CViewData* pViewData = m_pNode->GetViewData();
  1042. if (NULL == pViewData)
  1043. {
  1044. sc = E_UNEXPECTED;
  1045. return sc.ToHr();
  1046. }
  1047. pVerb->SetVerbSet(m_pNode->GetViewData()->GetVerbSet());
  1048. m_spConsoleVerb = pVerb;
  1049. if (NULL == m_spConsoleVerb)
  1050. {
  1051. sc = E_NOINTERFACE;
  1052. return sc.ToHr();
  1053. }
  1054. }
  1055. *ppConsoleVerb = (IConsoleVerb*)m_spConsoleVerb;
  1056. (*ppConsoleVerb)->AddRef();
  1057. return sc.ToHr();
  1058. }
  1059. //+-------------------------------------------------------------------
  1060. //
  1061. // Member: CNodeInitObject::NewWindow
  1062. //
  1063. // Synopsis: Create a new window from given node.
  1064. //
  1065. // Arguments: [hScopeItem] - Root of new window.
  1066. // [lOptions] - New window options.
  1067. //
  1068. // Returns: HRESULT
  1069. //
  1070. //--------------------------------------------------------------------
  1071. STDMETHODIMP CNodeInitObject::NewWindow(HSCOPEITEM hScopeItem, unsigned long lOptions)
  1072. {
  1073. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::NewWindow"));
  1074. if (!hScopeItem)
  1075. {
  1076. sc = E_INVALIDARG;
  1077. TraceSnapinError(_T("NULL HSCOPEITEM"), sc);
  1078. return sc.ToHr();
  1079. }
  1080. CConsoleFrame* pFrame = GetConsoleFrame();
  1081. if (pFrame == NULL)
  1082. {
  1083. sc = E_UNEXPECTED;
  1084. return sc.ToHr();
  1085. }
  1086. CMTNode* pMTNode = CMTNode::FromScopeItem (hScopeItem);
  1087. if (NULL == pMTNode)
  1088. {
  1089. sc = E_UNEXPECTED;
  1090. return sc.ToHr();
  1091. }
  1092. CreateNewViewStruct cnvs;
  1093. cnvs.idRootNode = pMTNode->GetID();
  1094. cnvs.lWindowOptions = lOptions;
  1095. cnvs.fVisible = true;
  1096. sc = pFrame->ScCreateNewView(&cnvs).ToHr();
  1097. return sc.ToHr();
  1098. }
  1099. //+-------------------------------------------------------------------
  1100. //
  1101. // Member: CNodeInitObject::Expand
  1102. //
  1103. // Synopsis: Visually expand or collapse an item.
  1104. //
  1105. // Arguments: [hScopeItem] - Item to be expanded/collapsed.
  1106. // [bExpand] - Expand/Collapse.
  1107. //
  1108. // Returns: HRESULT
  1109. //
  1110. //--------------------------------------------------------------------
  1111. STDMETHODIMP CNodeInitObject::Expand( HSCOPEITEM hScopeItem, BOOL bExpand)
  1112. {
  1113. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::Expand"));
  1114. if (m_pNode == NULL || m_pNode->GetViewData() == NULL)
  1115. {
  1116. sc = E_FAIL;
  1117. return sc.ToHr();
  1118. }
  1119. long id = 0;
  1120. CMTNode* pMTNode = CMTNode::FromScopeItem (hScopeItem);
  1121. if (pMTNode == NULL)
  1122. {
  1123. sc = E_INVALIDARG;
  1124. TraceSnapinError(_T("NULL HSCOPEITEM"), sc);
  1125. return sc.ToHr();
  1126. }
  1127. id = pMTNode->GetID();
  1128. {
  1129. /*
  1130. * tell this node's view to expand the node (use only this node's
  1131. * view, don't default to the active view if we have no node)
  1132. */
  1133. CConsoleView* pConsoleView = GetConsoleView (false);
  1134. if (pConsoleView == NULL)
  1135. {
  1136. sc = E_UNEXPECTED;
  1137. return sc.ToHr();
  1138. }
  1139. sc = pConsoleView->ScExpandNode (id, bExpand, true);
  1140. }
  1141. return (sc.ToHr());
  1142. }
  1143. //+-------------------------------------------------------------------
  1144. //
  1145. // Member: CNodeInitObject::IsTaskpadViewPreferred
  1146. //
  1147. // Synopsis: Obsolete method.
  1148. //
  1149. // Arguments:
  1150. //
  1151. // Returns: HRESULT
  1152. //
  1153. //--------------------------------------------------------------------
  1154. STDMETHODIMP CNodeInitObject::IsTaskpadViewPreferred()
  1155. {
  1156. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::IsTaskpadViewPreferred"));
  1157. /*
  1158. * taskpads always "preferred"
  1159. */
  1160. return sc.ToHr();
  1161. }
  1162. //+-------------------------------------------------------------------
  1163. //
  1164. // Member: CNodeInitObject::SetStatusText
  1165. //
  1166. // Synopsis: Change status bar text.
  1167. //
  1168. // Arguments: [pszStatusBarText]
  1169. //
  1170. // Returns: HRESULT
  1171. //
  1172. //--------------------------------------------------------------------
  1173. STDMETHODIMP CNodeInitObject::SetStatusText (LPOLESTR pszStatusBarText)
  1174. {
  1175. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::SetStatusText"));
  1176. if (m_pMTNode == NULL)
  1177. {
  1178. sc = E_FAIL;
  1179. return sc.ToHr();
  1180. }
  1181. if (m_pNode == NULL)
  1182. {
  1183. sc = E_FAIL;
  1184. return sc.ToHr();
  1185. }
  1186. CViewData* pViewData = m_pNode->GetViewData();
  1187. if (NULL == pViewData)
  1188. {
  1189. sc = E_UNEXPECTED;
  1190. return sc.ToHr();
  1191. }
  1192. CNode* pSelectedNode = pViewData->GetSelectedNode();
  1193. if (pSelectedNode == NULL)
  1194. {
  1195. sc = E_FAIL;
  1196. return sc.ToHr();
  1197. }
  1198. CMTNode* pMTSelectedNode = pSelectedNode->GetMTNode();
  1199. if (NULL == pMTSelectedNode)
  1200. {
  1201. sc = E_UNEXPECTED;
  1202. return sc.ToHr();
  1203. }
  1204. /*
  1205. * fail if not from the selected node's branch of the scope tree
  1206. */
  1207. if (m_pMTNode->GetStaticParent() != pMTSelectedNode->GetStaticParent())
  1208. {
  1209. sc = E_FAIL;
  1210. return sc.ToHr();
  1211. }
  1212. COMPONENTID nOwnerID = pSelectedNode->GetOwnerID();
  1213. COMPONENTID nID;
  1214. GetComponentID(&nID);
  1215. /*
  1216. * fail if not either the selected component or the static node
  1217. */
  1218. if (!((nOwnerID == nID) || ((nOwnerID == TVOWNED_MAGICWORD) && (nID == 0))))
  1219. {
  1220. sc = E_FAIL;
  1221. return sc.ToHr();
  1222. }
  1223. CConsoleStatusBar* pStatusBar = pViewData->GetStatusBar();
  1224. if (pStatusBar == NULL)
  1225. {
  1226. sc = E_FAIL;
  1227. return sc.ToHr();
  1228. }
  1229. USES_CONVERSION;
  1230. sc = pStatusBar->ScSetStatusText (W2CT (pszStatusBarText));
  1231. return (sc.ToHr());
  1232. }
  1233. /*+-------------------------------------------------------------------------*
  1234. *
  1235. * CNodeInitObject::RenameScopeItem
  1236. *
  1237. * PURPOSE: Puts the specified scope item into rename mode.
  1238. *
  1239. * PARAMETERS:
  1240. * HSCOPEITEM hScopeItem :
  1241. *
  1242. * RETURNS:
  1243. * STDMETHODIMP
  1244. *
  1245. *+-------------------------------------------------------------------------*/
  1246. STDMETHODIMP
  1247. CNodeInitObject::RenameScopeItem(HSCOPEITEM hScopeItem)
  1248. {
  1249. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, TEXT("IConsole3::RenameScopeItem"));
  1250. CMTNode* pMTNode = CMTNode::FromScopeItem (hScopeItem);
  1251. if (pMTNode == NULL)
  1252. {
  1253. sc = E_INVALIDARG;
  1254. TraceSnapinError(_T("NULL HSCOPEITEM"), sc);
  1255. return sc.ToHr();
  1256. }
  1257. // get the console view object
  1258. CConsoleView* pConsoleView = GetConsoleView (true); // default to the active view if m_pNode == NULL
  1259. if (pConsoleView == NULL)
  1260. return (sc = E_UNEXPECTED).ToHr();
  1261. sc = pConsoleView->ScRenameScopeNode(CMTNode::ToHandle(pMTNode) /*convert to HMTNODE*/);
  1262. return sc.ToHr();
  1263. }
  1264. /*+-------------------------------------------------------------------------*
  1265. * CNodeInitObject::GetStatusBar
  1266. *
  1267. * Returns the status bar interface for the CNodeInitObject.
  1268. *--------------------------------------------------------------------------*/
  1269. CConsoleStatusBar* CNodeInitObject::GetStatusBar(
  1270. bool fDefaultToActive /* =true */) const
  1271. {
  1272. CConsoleStatusBar* pStatusBar = NULL;
  1273. /*
  1274. * if we have a node, get the status bar from its view data
  1275. */
  1276. if (m_pNode != NULL)
  1277. {
  1278. ASSERT (m_pNode->GetViewData() != NULL);
  1279. pStatusBar = m_pNode->GetViewData()->GetStatusBar();
  1280. }
  1281. /*
  1282. * if we don't have a status bar yet, ask the main frame which one to use
  1283. */
  1284. if ((pStatusBar == NULL) && fDefaultToActive)
  1285. {
  1286. CConsoleFrame* pFrame = GetConsoleFrame();
  1287. ASSERT (pFrame != NULL);
  1288. if (pFrame != NULL)
  1289. pFrame->ScGetActiveStatusBar(pStatusBar);
  1290. }
  1291. return (pStatusBar);
  1292. }
  1293. /*+-------------------------------------------------------------------------*
  1294. * CNodeInitObject::GetConsoleView
  1295. *
  1296. * Returns the status bar interface for the CNodeInitObject.
  1297. *--------------------------------------------------------------------------*/
  1298. CConsoleView* CNodeInitObject::GetConsoleView (
  1299. bool fDefaultToActive /* =true */) const
  1300. {
  1301. CConsoleView* pConsoleView = NULL;
  1302. /*
  1303. * if we have a node, get the console view from its view data
  1304. */
  1305. if (m_pNode != NULL)
  1306. {
  1307. ASSERT (m_pNode->GetViewData() != NULL);
  1308. pConsoleView = m_pNode->GetViewData()->GetConsoleView();
  1309. }
  1310. /*
  1311. * if we don't have a console view yet and we want to default to the
  1312. * active view, ask the main frame which one to use
  1313. */
  1314. if ((pConsoleView == NULL) && fDefaultToActive)
  1315. {
  1316. CConsoleFrame* pFrame = GetConsoleFrame();
  1317. ASSERT (pFrame != NULL);
  1318. if (pFrame != NULL)
  1319. pFrame->ScGetActiveConsoleView (pConsoleView);
  1320. }
  1321. return (pConsoleView);
  1322. }
  1323. /*+-------------------------------------------------------------------------*
  1324. * CNodeInitObject::GetConsoleFrame
  1325. *
  1326. * Returns the CConsoleFrame interface for the console.
  1327. *--------------------------------------------------------------------------*/
  1328. CConsoleFrame* CNodeInitObject::GetConsoleFrame() const
  1329. {
  1330. CConsoleFrame* pFrame = NULL;
  1331. CScopeTree* pTree = dynamic_cast<CScopeTree*>(m_spScopeTree.GetInterfacePtr());
  1332. ASSERT (pTree != NULL);
  1333. if (pTree != NULL)
  1334. pFrame = pTree->GetConsoleFrame();
  1335. return (pFrame);
  1336. }
  1337. /*+-------------------------------------------------------------------------*
  1338. * STRING_TABLE_FORWARDER_PROLOG
  1339. *
  1340. * Standard prolog code for IStringTable forwarder functions.
  1341. *--------------------------------------------------------------------------*/
  1342. #define STRING_TABLE_FORWARDER_PROLOG(clsid, pSTP) \
  1343. CLSID clsid; \
  1344. VERIFY (SUCCEEDED (GetSnapinCLSID (clsid))); \
  1345. \
  1346. IStringTablePrivate* pSTP = CScopeTree::GetStringTable(); \
  1347. \
  1348. if (pSTP == NULL) \
  1349. return (E_FAIL); \
  1350. else \
  1351. (void) 0
  1352. //+-------------------------------------------------------------------
  1353. //
  1354. // Member: CNodeInitObject::AddString
  1355. //
  1356. // Synopsis: Add a string to the string table.
  1357. //
  1358. // Arguments: [pszAdd] - string to add
  1359. // [pID] - ret, string id.
  1360. //
  1361. // Returns: HRESULT
  1362. //
  1363. //--------------------------------------------------------------------
  1364. STDMETHODIMP CNodeInitObject::AddString (
  1365. LPCOLESTR pszAdd,
  1366. MMC_STRING_ID* pID)
  1367. {
  1368. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IStringTable::AddString"));
  1369. STRING_TABLE_FORWARDER_PROLOG (clsid, pStringTablePrivate);
  1370. sc = pStringTablePrivate->AddString (pszAdd, pID, &clsid);
  1371. return sc.ToHr();
  1372. }
  1373. //+-------------------------------------------------------------------
  1374. //
  1375. // Member: CNodeInitObject::GetString
  1376. //
  1377. // Synopsis: Get the string represented by given id.
  1378. //
  1379. // Arguments: [id]
  1380. // [cchBuffer] - Size of buffer.
  1381. // [lpBuffer]
  1382. // [pchchOut]
  1383. //
  1384. // Returns: HRESULT
  1385. //
  1386. //--------------------------------------------------------------------
  1387. STDMETHODIMP CNodeInitObject::GetString (
  1388. MMC_STRING_ID id,
  1389. ULONG cchBuffer,
  1390. LPOLESTR lpBuffer,
  1391. ULONG* pcchOut)
  1392. {
  1393. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IStringTable::GetString"));
  1394. STRING_TABLE_FORWARDER_PROLOG (clsid, pStringTablePrivate);
  1395. sc = pStringTablePrivate->GetString (id, cchBuffer, lpBuffer, pcchOut, &clsid);
  1396. return sc.ToHr();
  1397. }
  1398. //+-------------------------------------------------------------------
  1399. //
  1400. // Member: CNodeInitObject::GetStringLength
  1401. //
  1402. // Synopsis: Get the length of string represented by given string id.
  1403. //
  1404. // Arguments: [id] - string id.
  1405. // [pcchString] - ret ptr to len.
  1406. //
  1407. // Returns: HRESULT
  1408. //
  1409. //--------------------------------------------------------------------
  1410. STDMETHODIMP CNodeInitObject::GetStringLength (
  1411. MMC_STRING_ID id,
  1412. ULONG* pcchString)
  1413. {
  1414. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IStringTable::GetStringLength"));
  1415. STRING_TABLE_FORWARDER_PROLOG (clsid, pStringTablePrivate);
  1416. sc = pStringTablePrivate->GetStringLength (id, pcchString, &clsid);
  1417. return sc.ToHr();
  1418. }
  1419. //+-------------------------------------------------------------------
  1420. //
  1421. // Member: CNodeInitObject::DeleteString
  1422. //
  1423. // Synopsis: Delete the string represented by given string id.
  1424. //
  1425. // Arguments: [id]
  1426. //
  1427. // Returns: HRESULT
  1428. //
  1429. //--------------------------------------------------------------------
  1430. STDMETHODIMP CNodeInitObject::DeleteString (
  1431. MMC_STRING_ID id)
  1432. {
  1433. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IStringTable::DeleteString"));
  1434. STRING_TABLE_FORWARDER_PROLOG (clsid, pStringTablePrivate);
  1435. sc = pStringTablePrivate->DeleteString (id, &clsid);
  1436. return sc.ToHr();
  1437. }
  1438. //+-------------------------------------------------------------------
  1439. //
  1440. // Member: CNodeInitObject::DeleteAllStrings
  1441. //
  1442. // Synopsis: Delete all strings (for this snapin).
  1443. //
  1444. // Arguments:
  1445. //
  1446. // Returns: HRESULT
  1447. //
  1448. //--------------------------------------------------------------------
  1449. STDMETHODIMP CNodeInitObject::DeleteAllStrings ()
  1450. {
  1451. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IStringTable::DeleteAllStrings"));
  1452. STRING_TABLE_FORWARDER_PROLOG (clsid, pStringTablePrivate);
  1453. sc = pStringTablePrivate->DeleteAllStrings (&clsid);
  1454. return sc.ToHr();
  1455. }
  1456. //+-------------------------------------------------------------------
  1457. //
  1458. // Member: CNodeInitObject::FindString
  1459. //
  1460. // Synopsis: Find if given string exists, if so ret its string-id.
  1461. //
  1462. // Arguments: [pszFind] - string to find.
  1463. // [pID] - string id (retval).
  1464. //
  1465. // Returns: HRESULT
  1466. //
  1467. //--------------------------------------------------------------------
  1468. STDMETHODIMP CNodeInitObject::FindString (
  1469. LPCOLESTR pszFind,
  1470. MMC_STRING_ID* pID)
  1471. {
  1472. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IStringTable::FindString"));
  1473. STRING_TABLE_FORWARDER_PROLOG (clsid, pStringTablePrivate);
  1474. sc = pStringTablePrivate->FindString (pszFind, pID, &clsid);
  1475. return sc.ToHr();
  1476. }
  1477. //+-------------------------------------------------------------------
  1478. //
  1479. // Member: CNodeInitObject::Enumerate
  1480. //
  1481. // Synopsis: Get an enumerator to (this snapins) string table.
  1482. //
  1483. // Arguments: [ppEnum]
  1484. //
  1485. // Returns: HRESULT
  1486. //
  1487. //--------------------------------------------------------------------
  1488. STDMETHODIMP CNodeInitObject::Enumerate (
  1489. IEnumString** ppEnum)
  1490. {
  1491. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IStringTable::Enumerate"));
  1492. STRING_TABLE_FORWARDER_PROLOG (clsid, pStringTablePrivate);
  1493. sc = pStringTablePrivate->Enumerate (ppEnum, &clsid);
  1494. return sc.ToHr();
  1495. }
  1496. /*+-------------------------------------------------------------------------*
  1497. * CNodeInitObject::GetSnapinCLSID
  1498. *
  1499. *
  1500. *--------------------------------------------------------------------------*/
  1501. HRESULT CNodeInitObject::GetSnapinCLSID (CLSID& clsid) const
  1502. {
  1503. SC sc; // We do not want to break if this function returns failure
  1504. // so we do not use DECLARE_SC.
  1505. ASSERT (!IsBadWritePtr (&clsid, sizeof (CLSID)));
  1506. if (NULL == m_pMTNode)
  1507. {
  1508. sc = E_UNEXPECTED;
  1509. return sc.ToHr();
  1510. }
  1511. CSnapIn* pSnapin = m_pMTNode->GetPrimarySnapIn();
  1512. if (NULL == pSnapin)
  1513. {
  1514. sc = E_UNEXPECTED;
  1515. return sc.ToHr();
  1516. }
  1517. clsid = pSnapin->GetSnapInCLSID();
  1518. return sc.ToHr();
  1519. }
  1520. /***************************************************************************\
  1521. *
  1522. * METHOD: CNodeInitObject::ReleaseCachedOleObjects
  1523. *
  1524. * PURPOSE: Releases cached OLE objects. Calls are made from CONUI
  1525. *
  1526. * PARAMETERS:
  1527. *
  1528. * RETURNS:
  1529. * SC - result code
  1530. *
  1531. \***************************************************************************/
  1532. HRESULT CNodeInitObject::ReleaseCachedOleObjects()
  1533. {
  1534. DECLARE_SC(sc, TEXT("CNodeInitObject::GetSnapinCLSID"));
  1535. sc = COleCacheCleanupManager::ScReleaseCachedOleObjects();
  1536. if (sc)
  1537. return sc.ToHr();
  1538. return sc.ToHr();
  1539. }