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.

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