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.

1230 lines
33 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: rsltdata.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "menuitem.h" // MENUITEM_BASE_ID
  12. #include "amcmsgid.h"
  13. #include "conview.h"
  14. #include "rsltitem.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. //+-------------------------------------------------------------------
  20. //
  21. // Member: CNodeInitObject::SetResultView
  22. //
  23. // Synopsis: Save the result view ptr.
  24. //
  25. // Arguments: [pUnknown] -
  26. //
  27. // Returns: HRESULT
  28. //
  29. //--------------------------------------------------------------------
  30. STDMETHODIMP CNodeInitObject::SetResultView(LPUNKNOWN pUnknown)
  31. {
  32. DECLARE_SC(sc, _T("CNodeInitObject::SetResultView"));
  33. m_spResultViewUnk = pUnknown;
  34. m_spListViewPrivate = pUnknown;
  35. // If the resultview is reset then reset the desc bar.
  36. if (NULL == pUnknown)
  37. SetDescBarText( L"" );
  38. return sc.ToHr();
  39. }
  40. //+-------------------------------------------------------------------
  41. //
  42. // Member: CNodeInitObject::IsResultViewSet
  43. //
  44. // Synopsis: Is the ResultView ptr set (so that conui can query
  45. // before invoking ResultView methods).
  46. //
  47. // Arguments: [pbIsLVSet] - Ptr to BOOL. (TRUE means ResultView is set).
  48. //
  49. // Returns: HRESULT
  50. //
  51. //--------------------------------------------------------------------
  52. STDMETHODIMP CNodeInitObject::IsResultViewSet(BOOL* pbIsLVSet)
  53. {
  54. DECLARE_SC(sc, _T("CNodeInitObject::IsResultViewSet"));
  55. sc = ScCheckPointers(pbIsLVSet);
  56. if (sc)
  57. return sc.ToHr();
  58. *pbIsLVSet = FALSE;
  59. if (m_spListViewPrivate)
  60. *pbIsLVSet = TRUE;
  61. return sc.ToHr();
  62. }
  63. //+-------------------------------------------------------------------
  64. //
  65. // Member: CNodeInitObject::SetTaskPadList
  66. //
  67. // Synopsis:
  68. //
  69. // Arguments:
  70. //
  71. // Returns: HRESULT
  72. //
  73. //--------------------------------------------------------------------
  74. STDMETHODIMP CNodeInitObject::SetTaskPadList(LPUNKNOWN pUnknown)
  75. {
  76. DECLARE_SC(sc, _T("CNodeInitObject::SetTaskPadList"));
  77. if (pUnknown == NULL)
  78. {
  79. m_spListViewPrivate = NULL;
  80. }
  81. else
  82. {
  83. if (m_spListViewPrivate == pUnknown)
  84. {
  85. return sc.ToHr();
  86. }
  87. else
  88. {
  89. ASSERT(m_spListViewPrivate == NULL);
  90. m_spListViewPrivate = pUnknown;
  91. }
  92. }
  93. return sc.ToHr();
  94. }
  95. //+-------------------------------------------------------------------
  96. //
  97. // Member: CNodeInitObject::QueryResultView
  98. //
  99. // Synopsis: IConsole2 method for snapins to get resultview's IUnknown.
  100. //
  101. // Arguments: [ppUnk] - return IUnknown to snapin.
  102. //
  103. // Returns: HRESULT
  104. //
  105. //--------------------------------------------------------------------
  106. STDMETHODIMP CNodeInitObject::QueryResultView(LPUNKNOWN* ppUnk)
  107. {
  108. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::QueryResultView"));
  109. if (!ppUnk)
  110. {
  111. sc = E_INVALIDARG;
  112. TraceSnapinError(_T("Null LPUNKNOWN pointer passed in"), sc);
  113. return sc.ToHr();
  114. }
  115. (*ppUnk) = m_spResultViewUnk;
  116. sc = ScCheckPointers((*ppUnk), E_UNEXPECTED);
  117. if (sc)
  118. return sc.ToHr();
  119. (*ppUnk)->AddRef();
  120. return sc.ToHr();
  121. }
  122. //+-------------------------------------------------------------------
  123. //
  124. // Member: CNodeInitObject::MessageBox
  125. //
  126. // Synopsis: IConsole2 member, called by snapin to display a message box.
  127. //
  128. // Arguments: [lpszText] - Text to display.
  129. // [lpszTitle] -
  130. // [fuStyle] -
  131. // [piRetval] -
  132. //
  133. // Returns: HRESULT
  134. //
  135. //--------------------------------------------------------------------
  136. STDMETHODIMP CNodeInitObject::MessageBox(
  137. LPCWSTR lpszText, LPCWSTR lpszTitle, UINT fuStyle, int* piRetval)
  138. {
  139. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IConsole2::MessageBox"));
  140. USES_CONVERSION;
  141. // find the main frame window and use it as the owner of the message box
  142. INT iRetval = ::MessageBox(
  143. GetMainWindow(),
  144. W2CT(lpszText),
  145. W2CT(lpszTitle),
  146. fuStyle );
  147. if (NULL != piRetval)
  148. *piRetval = iRetval;
  149. return sc.ToHr();
  150. }
  151. //+-------------------------------------------------------------------
  152. //
  153. // Member: CNodeInitObject::GetListStyle
  154. //
  155. // Synopsis: Get the current list view style.
  156. //
  157. // Arguments: [pStyle] -
  158. //
  159. // Note: IResultDataPrivate member, internal to MMC.
  160. //
  161. // Returns: HRESULT
  162. //
  163. //--------------------------------------------------------------------
  164. STDMETHODIMP CNodeInitObject::GetListStyle(long * pStyle)
  165. {
  166. DECLARE_SC(sc, _T("CNodeInitObject::GetListStyle"));
  167. // must have pStyle
  168. if (!pStyle)
  169. {
  170. sc = E_INVALIDARG;
  171. TraceError(_T("CNodeinitObject::GetListStyle, style ptr passed is NULL"), sc);
  172. return sc.ToHr();
  173. }
  174. if (NULL == m_spListViewPrivate)
  175. {
  176. sc = E_UNEXPECTED;
  177. TraceError(_T("CNodeinitObject::GetListStyle, ListView ptr is NULL"), sc);
  178. return sc.ToHr();
  179. }
  180. *pStyle = m_spListViewPrivate->GetListStyle();
  181. return sc.ToHr();
  182. }
  183. //+-------------------------------------------------------------------
  184. //
  185. // Member: CNodeInitObject::SetListStyle
  186. //
  187. // Synopsis: Modify the list view style.
  188. //
  189. // Arguments: [style] -
  190. //
  191. // Note: IResultDataPrivate member, internal to MMC.
  192. //
  193. // Returns: HRESULT
  194. //
  195. //--------------------------------------------------------------------
  196. STDMETHODIMP CNodeInitObject::SetListStyle(long style)
  197. {
  198. DECLARE_SC(sc, _T("CNodeInitObject::SetListStyle"));
  199. if (NULL == m_spListViewPrivate)
  200. {
  201. sc = E_UNEXPECTED;
  202. TraceError(_T("CNodeinitObject::GetListStyle, ListView ptr is NULL"), sc);
  203. return sc.ToHr();
  204. }
  205. sc = m_spListViewPrivate->SetListStyle(style);
  206. return sc.ToHr();
  207. }
  208. //+-------------------------------------------------------------------
  209. //
  210. // Member: CNodeInitObject::ModifyItemState
  211. //
  212. // Synopsis: Enables snapin to modify the state of an item.
  213. //
  214. // Arguments: [nIndex] - index of the item to be modified (used only if itemID is 0).
  215. // [itemID] - HRESULTITEM if not virtual-list (Virtual list use above index).
  216. // [uAdd] - States to add.
  217. // [uRemove] - States to be removed.
  218. //
  219. // Returns: HRESULT
  220. //
  221. //--------------------------------------------------------------------
  222. STDMETHODIMP CNodeInitObject::ModifyItemState(int nIndex, HRESULTITEM hri,
  223. UINT uAdd, UINT uRemove)
  224. {
  225. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::ModifyItemState"));
  226. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  227. if (sc)
  228. return sc.ToHr();
  229. sc = m_spListViewPrivate->ModifyItemState(nIndex, CResultItem::FromHandle(hri), uAdd, uRemove);
  230. return sc.ToHr();
  231. }
  232. //+-------------------------------------------------------------------
  233. //
  234. // Member: CNodeInitObject::ModifyViewStyle
  235. //
  236. // Synopsis: Allows snapin to modify list view style.
  237. //
  238. // Arguments: [add] - Styles to be set.
  239. // [remove] - Styles to be removed.
  240. //
  241. // Returns: HRESULT
  242. //
  243. //--------------------------------------------------------------------
  244. STDMETHODIMP CNodeInitObject::ModifyViewStyle(MMC_RESULT_VIEW_STYLE add,
  245. MMC_RESULT_VIEW_STYLE remove)
  246. {
  247. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::ModifyViewStyle"));
  248. typedef struct {
  249. MMC_RESULT_VIEW_STYLE mmcFlag;
  250. DWORD lvsFlag;
  251. } FlagMapEntry;
  252. FlagMapEntry flagMap[] =
  253. {
  254. {MMC_SINGLESEL, LVS_SINGLESEL},
  255. {MMC_SHOWSELALWAYS, LVS_SHOWSELALWAYS},
  256. {MMC_NOSORTHEADER, LVS_NOSORTHEADER},
  257. {MMC_ENSUREFOCUSVISIBLE, MMC_LVS_ENSUREFOCUSVISIBLE},
  258. {(MMC_RESULT_VIEW_STYLE)0, 0}
  259. };
  260. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  261. if (sc)
  262. return sc.ToHr();
  263. // Get the old style.
  264. DWORD dwLVStyle = static_cast<DWORD>(m_spListViewPrivate->GetListStyle());
  265. // convert MMC_ flags to LVS_ flags and apply to current style
  266. for (FlagMapEntry* pMap = flagMap; pMap->mmcFlag; pMap++)
  267. {
  268. if (add & pMap->mmcFlag)
  269. dwLVStyle |= pMap->lvsFlag;
  270. if (remove & pMap->mmcFlag)
  271. dwLVStyle &= ~pMap->lvsFlag;
  272. }
  273. sc = m_spListViewPrivate->SetListStyle(static_cast<long>(dwLVStyle));
  274. return sc.ToHr();
  275. }
  276. //+-------------------------------------------------------------------
  277. //
  278. // Member: CNodeInitObject::InsertItem
  279. //
  280. // Synopsis: Insert an item into ListView (IResultData member).
  281. //
  282. // Arguments: [item] -
  283. //
  284. // Returns: HRESULT
  285. //
  286. //--------------------------------------------------------------------
  287. STDMETHODIMP CNodeInitObject::InsertItem(LPRESULTDATAITEM item)
  288. {
  289. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::InsertItem"));
  290. // MUST have an item structure.
  291. if (!item)
  292. {
  293. sc = E_INVALIDARG;
  294. TraceSnapinError(_T("The LPRESULTDATAITEM ptr passed in is NULL"), sc);
  295. return sc.ToHr();
  296. }
  297. COMPONENTID nID;
  298. GetComponentID(&nID);
  299. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  300. if (sc)
  301. return sc.ToHr();
  302. CResultItem* pri = NULL;
  303. sc = m_spListViewPrivate->InsertItem(
  304. item->mask & RDI_STR ? item->str : MMCLV_NOPTR,
  305. item->mask & RDI_IMAGE ? item->nImage : MMCLV_NOICON,
  306. item->mask & RDI_PARAM ? item->lParam : MMCLV_NOPARAM,
  307. item->mask & RDI_STATE ? item->nState : MMCLV_NOPARAM,
  308. nID, item->nIndex, pri);
  309. if (sc)
  310. return (sc.ToHr());
  311. if (pri == NULL)
  312. return ((sc = E_UNEXPECTED).ToHr());
  313. item->itemID = CResultItem::ToHandle(pri);
  314. return sc.ToHr();
  315. }
  316. //+-------------------------------------------------------------------
  317. //
  318. // Member: CNodeInitObject::DeleteItem
  319. //
  320. // Synopsis: Delete the given item (IResultData member).
  321. //
  322. // Arguments: [itemID] - item identifier.
  323. // [nCol] - column to delete.
  324. //
  325. // Note: nCol must be zero.
  326. //
  327. // Returns: HREsULT
  328. //
  329. //--------------------------------------------------------------------
  330. STDMETHODIMP CNodeInitObject::DeleteItem(HRESULTITEM itemID, int nCol)
  331. {
  332. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::DeleteItem"));
  333. if (nCol != 0)
  334. {
  335. sc = E_INVALIDARG;
  336. TraceSnapinError(_T("Column index must be zero"), sc);
  337. return sc.ToHr();
  338. }
  339. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  340. if (sc)
  341. return sc.ToHr();
  342. sc = m_spListViewPrivate->DeleteItem ( itemID, nCol);
  343. return sc.ToHr();
  344. }
  345. //+-------------------------------------------------------------------
  346. //
  347. // Member: CNodeInitObject::UpdateItem
  348. //
  349. // Synopsis: Redraw the given item.
  350. //
  351. // Arguments: [itemID] - Item identifier.
  352. //
  353. // Returns: SC
  354. //
  355. //--------------------------------------------------------------------
  356. STDMETHODIMP CNodeInitObject::UpdateItem(HRESULTITEM itemID)
  357. {
  358. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::UpdateItem"));
  359. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  360. if (sc)
  361. return sc.ToHr();
  362. sc = m_spListViewPrivate->UpdateItem(itemID);
  363. if (sc)
  364. return sc.ToHr();
  365. return sc.ToHr();
  366. }
  367. //+-------------------------------------------------------------------
  368. //
  369. // Member: Sort
  370. //
  371. // Synopsis: IResultData member, snapins can call this to sort the
  372. // result pane items. This calls InternalSort to do sort.
  373. //
  374. // Arguments: [nCol] - Column to be sorted.
  375. // [dwSortOptions] - Sort options.
  376. // [lUserParam] - User (snapin) param.
  377. //
  378. // Returns: HRESULT
  379. //
  380. // History: RaviR Created
  381. //
  382. //--------------------------------------------------------------------
  383. STDMETHODIMP CNodeInitObject::Sort(int nCol, DWORD dwSortOptions, LPARAM lUserParam)
  384. {
  385. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::Sort"));
  386. sc = ScCheckPointers(m_spComponent, E_UNEXPECTED);
  387. if (sc)
  388. return sc.ToHr();
  389. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  390. if (sc)
  391. return sc.ToHr();
  392. int nColumnCnt;
  393. sc = m_spListViewPrivate->GetColumnCount(&nColumnCnt);
  394. if (sc)
  395. return sc.ToHr();
  396. if (nCol < 0 || nCol >= nColumnCnt)
  397. {
  398. sc = E_INVALIDARG;
  399. TraceSnapinError(_T("Column index is invalid"), sc);
  400. return sc.ToHr();
  401. }
  402. sc = InternalSort(nCol, dwSortOptions, lUserParam, FALSE);
  403. return sc.ToHr();
  404. }
  405. //+-------------------------------------------------------------------
  406. //
  407. // Member: InternalSort
  408. //
  409. // Synopsis: Private member MMC calls to sort the result pane items.
  410. //
  411. // Arguments: [nCol] - Column to be sorted.
  412. // [dwSortOptions] - Sort options.
  413. // [lUserParam] - User (snapin) param.
  414. // [bColumnClicked] - Is sort due to column click.
  415. //
  416. // Note: If column is clicked the lUserParam will be NULL.
  417. // The sort options is set depending on ascend/descend,
  418. // and cannot include RSI_NOSORTICON as this option is
  419. // only for snapin initiated sort.
  420. //
  421. // Returns: HRESULT
  422. //
  423. // History: RaviR Created
  424. // 07-02-1999 AnandhaG added setsorticon.
  425. //--------------------------------------------------------------------
  426. STDMETHODIMP CNodeInitObject::InternalSort(INT nCol, DWORD dwSortOptions,
  427. LPARAM lUserParam, BOOL bColumnClicked)
  428. {
  429. DECLARE_SC(sc, _T("CNodeInitObject::InternalSort"));
  430. // Save old sort-column to reset its sort icon.
  431. int nOldCol = m_sortParams.nCol;
  432. BOOL bAscending = m_sortParams.bAscending;
  433. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  434. if (sc)
  435. return sc.ToHr();
  436. // If column is clicked the sortoption and user param are
  437. // already 0. Set only the sortoptions below.
  438. if (bColumnClicked)
  439. {
  440. if(nOldCol != nCol)
  441. bAscending = TRUE;
  442. else
  443. bAscending = !m_sortParams.bAscending;
  444. dwSortOptions |= (bAscending ? 0 : RSI_DESCENDING);
  445. // Notify component of sort parameter change
  446. m_spComponent->Notify(NULL, MMCN_COLUMN_CLICK, nCol,dwSortOptions);
  447. }
  448. bool bIsVirtualList = false;
  449. sc = ScIsVirtualList(bIsVirtualList);
  450. if (sc)
  451. return sc.ToHr();
  452. if ( bIsVirtualList )
  453. {
  454. // see if the snap-in handle owner data methods
  455. IResultOwnerDataPtr pResultOwnerData = m_spComponent;
  456. if (pResultOwnerData != NULL)
  457. {
  458. sc = pResultOwnerData->SortItems(nCol,dwSortOptions,lUserParam );
  459. // if reordering done, save the sort data and repaint the list view.
  460. if (S_OK == sc.ToHr())
  461. {
  462. m_sortParams.nCol = nCol;
  463. m_sortParams.bAscending = !(dwSortOptions & RSI_DESCENDING);
  464. m_sortParams.bSetSortIcon = !(dwSortOptions & RSI_NOSORTICON);
  465. m_sortParams.lpUserParam = lUserParam;
  466. /*
  467. * Bug 414256: We need to save the sort data only if
  468. * it is user initiated sort. Is this user initiated?
  469. */
  470. m_sortParams.bUserInitiatedSort = bColumnClicked;
  471. sc = m_spListViewPrivate->Repaint(TRUE);
  472. if (sc)
  473. return sc.ToHr();
  474. }
  475. }
  476. else
  477. {
  478. sc = E_UNEXPECTED;
  479. }
  480. }
  481. else
  482. {
  483. // Query for compare interfaces
  484. IResultDataComparePtr spResultCompare = m_spComponent;
  485. IResultDataCompareExPtr spResultCompareEx = m_spComponent;
  486. // Set the sort parameters.
  487. m_sortParams.nCol = nCol;
  488. m_sortParams.bAscending = !(dwSortOptions & RSI_DESCENDING);
  489. m_sortParams.bSetSortIcon = !(dwSortOptions & RSI_NOSORTICON);
  490. m_sortParams.lpUserParam = lUserParam;
  491. m_sortParams.lpResultCompare = spResultCompare;
  492. m_sortParams.lpResultCompareEx = spResultCompareEx;
  493. /*
  494. * Bug 414256: We need to save the sort data only if
  495. * it is user initiated sort. Is this user initiated?
  496. */
  497. m_sortParams.bUserInitiatedSort = bColumnClicked;
  498. sc = m_spListViewPrivate->Sort(lUserParam, (long*)&m_sortParams);
  499. m_sortParams.lpResultCompare = NULL;
  500. m_sortParams.lpResultCompareEx = NULL;
  501. }
  502. // Set sort icon only if Sort went through.
  503. if (S_OK == sc.ToHr())
  504. {
  505. sc = m_spListViewPrivate->SetColumnSortIcon( m_sortParams.nCol, nOldCol,
  506. m_sortParams.bAscending,
  507. m_sortParams.bSetSortIcon);
  508. }
  509. return sc.ToHr();
  510. }
  511. /***************************************************************************\
  512. *
  513. * METHOD: CNodeInitObject::GetSortDirection
  514. *
  515. * PURPOSE: returns sorting direction
  516. *
  517. * PARAMETERS:
  518. * BOOL* pbAscending - resulting sort column dir
  519. *
  520. * RETURNS:
  521. * SC - result code. S_FALSE ( in combination with -1 col) if no sorting.
  522. *
  523. \***************************************************************************/
  524. STDMETHODIMP CNodeInitObject::GetSortDirection(BOOL* pbAscending)
  525. {
  526. DECLARE_SC(sc, TEXT("CNodeInitObject::GetSortDirection"));
  527. if (pbAscending == NULL)
  528. {
  529. sc = E_INVALIDARG;
  530. return sc.ToHr();
  531. }
  532. *pbAscending = m_sortParams.bAscending;
  533. // If no sorting is performed then return S_FALSE.
  534. sc = m_sortParams.nCol >= 0 ? S_OK : S_FALSE;
  535. return sc.ToHr();
  536. }
  537. /***************************************************************************\
  538. *
  539. * METHOD: CNodeInitObject::GetSortColumn
  540. *
  541. * PURPOSE: returns sorting column
  542. * sort column regardless if the user has initiated the sort or not.
  543. *
  544. * PARAMETERS:
  545. * INT* pnCol - resulting sort column index
  546. *
  547. * RETURNS:
  548. * SC - result code. S_FALSE ( in combination with -1 col) if no sorting.
  549. *
  550. \***************************************************************************/
  551. STDMETHODIMP CNodeInitObject::GetSortColumn(INT* pnCol)
  552. {
  553. DECLARE_SC(sc, TEXT("CNodeInitObject::GetSortColumn"));
  554. if (pnCol == NULL)
  555. {
  556. sc = E_INVALIDARG;
  557. return sc.ToHr();
  558. }
  559. *pnCol = m_sortParams.nCol;
  560. // return code depending if the valid column was got
  561. sc = m_sortParams.nCol >= 0 ? S_OK : S_FALSE;
  562. return sc.ToHr();
  563. }
  564. //+-------------------------------------------------------------------
  565. //
  566. // Member: CNodeInitObject::FindItemByLParam
  567. //
  568. // Synopsis: Find the ItemID using the user-param.
  569. //
  570. // Arguments: [lParam] - lParam (RESULTDATAITEM.lParam)
  571. // [pItemID] - return the item-id.
  572. //
  573. // Returns: HRESULT
  574. //
  575. //--------------------------------------------------------------------
  576. STDMETHODIMP CNodeInitObject::FindItemByLParam(LPARAM lParam, HRESULTITEM *pItemID)
  577. {
  578. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::FindItemByLParam"));
  579. if(!pItemID)
  580. {
  581. sc = E_INVALIDARG;
  582. TraceSnapinError(_T("the HRESULTITEM* ptr is NULL"), sc);
  583. return sc.ToHr();
  584. }
  585. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  586. if (sc)
  587. return sc.ToHr();
  588. COMPONENTID id;
  589. GetComponentID(&id);
  590. /*
  591. * init the output param
  592. */
  593. *pItemID = NULL;
  594. CResultItem* pri = NULL;
  595. sc = m_spListViewPrivate->FindItemByLParam (id, lParam, pri);
  596. if (sc == SC(E_FAIL)) // E_FAIL is legal return value.
  597. {
  598. sc.Clear();
  599. return E_FAIL;
  600. }
  601. sc = ScCheckPointers (pri, E_UNEXPECTED);
  602. if (sc)
  603. return (sc.ToHr());
  604. *pItemID = CResultItem::ToHandle(pri);
  605. return sc.ToHr();
  606. }
  607. //+-------------------------------------------------------------------
  608. //
  609. // Member: CNodeInitObject::DeleteAllRsltItems
  610. //
  611. // Synopsis: Delete all the result items
  612. //
  613. // Arguments:
  614. //
  615. // Returns: HRESULT
  616. //
  617. //--------------------------------------------------------------------
  618. STDMETHODIMP CNodeInitObject::DeleteAllRsltItems()
  619. {
  620. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::DeleteAllRsltItems"));
  621. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  622. if (sc)
  623. return sc.ToHr();
  624. COMPONENTID id;
  625. GetComponentID(&id);
  626. sc = m_spListViewPrivate->DeleteAllItems(id);
  627. return sc.ToHr();
  628. }
  629. //+-------------------------------------------------------------------
  630. //
  631. // Member: CNodeInitObject::SetItem
  632. //
  633. // Synopsis: Modify attributes of an item.
  634. //
  635. // Arguments: [item]
  636. //
  637. // Returns: HRESULT
  638. //
  639. //--------------------------------------------------------------------
  640. STDMETHODIMP CNodeInitObject::SetItem(LPRESULTDATAITEM item)
  641. {
  642. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::SetItem"));
  643. // MUST have an item structure.
  644. if (!item)
  645. {
  646. sc = E_INVALIDARG;
  647. TraceSnapinError(_T("NULL LPRESULTDATAITEM ptr"), sc);
  648. return sc.ToHr();
  649. }
  650. // Cannot set an lParam on a subItem. (thank Win32 for this)
  651. if((item->mask & RDI_PARAM) && (item->nCol != 0))
  652. {
  653. sc = E_INVALIDARG;
  654. TraceSnapinError(_T("Cannot set lParam for subitem"), sc);
  655. return sc.ToHr();
  656. }
  657. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  658. if (sc)
  659. return sc.ToHr();
  660. COMPONENTID id;
  661. GetComponentID(&id);
  662. CResultItem* pri = CResultItem::FromHandle (item->itemID);
  663. sc = m_spListViewPrivate->SetItem(
  664. item->nIndex,
  665. pri, item->nCol,
  666. item->mask & RDI_STR ? item->str : MMCLV_NOPTR,
  667. item->mask & RDI_IMAGE ? item->nImage : MMCLV_NOICON,
  668. item->mask & RDI_PARAM ? item->lParam : MMCLV_NOPARAM,
  669. item->mask & RDI_STATE ? item->nState : MMCLV_NOPARAM,
  670. id);
  671. return sc.ToHr();
  672. }
  673. //+-------------------------------------------------------------------
  674. //
  675. // Member: CNodeInitObject::GetNextItem
  676. //
  677. // Synopsis: Get the next item with specified flag set.
  678. //
  679. // Arguments:
  680. //
  681. // Returns: HRESULT
  682. //
  683. //--------------------------------------------------------------------
  684. STDMETHODIMP CNodeInitObject::GetNextItem(LPRESULTDATAITEM item)
  685. {
  686. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::GetNextItem"));
  687. if (NULL == item)
  688. {
  689. sc = E_INVALIDARG;
  690. TraceSnapinError(_T("NULL LPRESULTDATAITEM ptr"), sc);
  691. return sc.ToHr();
  692. }
  693. if (NULL == (item->mask & RDI_STATE))
  694. {
  695. sc = E_INVALIDARG;
  696. TraceSnapinError(_T("RDI_STATE mask not set"), sc);
  697. return sc.ToHr();
  698. }
  699. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  700. if (sc)
  701. return sc.ToHr();
  702. COMPONENTID id;
  703. GetComponentID(&id);
  704. bool bIsVirtualList = false;
  705. sc = ScIsVirtualList(bIsVirtualList);
  706. if (sc)
  707. return sc.ToHr();
  708. HRESULT hr = S_OK;
  709. long nIndex = item->nIndex;
  710. CResultItem* pri = NULL;
  711. // Assume error
  712. item->nIndex = -1;
  713. item->lParam = 0;
  714. while (1)
  715. {
  716. sc = m_spListViewPrivate->GetNextItem (id, nIndex, item->nState,
  717. pri, nIndex);
  718. if (sc.ToHr() != S_OK)
  719. {
  720. break;
  721. }
  722. // Virtual list item, just return the index (lParam is zero).
  723. if (bIsVirtualList)
  724. {
  725. item->nIndex = nIndex;
  726. item->bScopeItem = FALSE;
  727. break;
  728. }
  729. sc = ScCheckPointers (pri, E_FAIL);
  730. if (sc)
  731. break;
  732. // Non-virtual leaf item.
  733. if (pri->GetOwnerID() == id)
  734. {
  735. item->nIndex = nIndex;
  736. item->bScopeItem = FALSE;
  737. item->lParam = pri->GetSnapinData();
  738. break;
  739. }
  740. if (!pri->IsScopeItem())
  741. {
  742. sc = E_UNEXPECTED;
  743. break;
  744. }
  745. // This is a tree item, get the lUserParam.
  746. CNode* pNode = CNode::FromResultItem (pri);
  747. sc = ScCheckPointers(pNode, E_UNEXPECTED);
  748. if (sc)
  749. return sc.ToHr();
  750. if (pNode->IsStaticNode() == TRUE)
  751. break;
  752. CMTNode* pMTNode = pNode->GetMTNode();
  753. sc = ScCheckPointers(pMTNode, E_UNEXPECTED);
  754. if (sc)
  755. return sc.ToHr();
  756. if (pMTNode->GetPrimaryComponentID() == id)
  757. {
  758. item->nIndex = nIndex;
  759. item->bScopeItem = TRUE;
  760. item->lParam = pMTNode->GetUserParam();
  761. break;
  762. }
  763. }
  764. return sc.ToHr();
  765. }
  766. //+-------------------------------------------------------------------
  767. //
  768. // Member: CNodeInitObject::GetItem
  769. //
  770. // Synopsis: Get the parameters of an item.
  771. //
  772. // Arguments: [item] - itemID is used to get the item, if itemID = 0,
  773. // then nIndex is used.
  774. //
  775. // Note: For VLists itemID = 0, nIndex is used.
  776. // nCol must be zero.
  777. //
  778. // Returns: HRESULT
  779. //
  780. //--------------------------------------------------------------------
  781. STDMETHODIMP CNodeInitObject::GetItem(LPRESULTDATAITEM item)
  782. {
  783. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::GetItem"));
  784. // MUST have an item structure.
  785. if (!item)
  786. {
  787. sc = E_INVALIDARG;
  788. TraceSnapinError(_T("NULL LPRESULTDATAITEM ptr."), sc);
  789. return sc.ToHr();
  790. }
  791. COMPONENTID id;
  792. GetComponentID(&id);
  793. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  794. if (sc)
  795. return sc.ToHr();
  796. CResultItem* pri = NULL;
  797. sc = m_spListViewPrivate->GetItem(
  798. item->nIndex,
  799. pri, item->nCol,
  800. item->mask & RDI_STR ? &item->str : MMCLV_NOPTR,
  801. item->mask & RDI_IMAGE ? &item->nImage : MMCLV_NOPTR,
  802. item->mask & RDI_PARAM ? &item->lParam : MMCLV_NOPTR,
  803. item->mask & RDI_STATE ? &item->nState : MMCLV_NOPTR,
  804. &item->bScopeItem);
  805. if (sc)
  806. return (sc.ToHr());
  807. if (pri == NULL)
  808. return ((sc = E_UNEXPECTED).ToHr());
  809. if (pri->IsScopeItem())
  810. {
  811. item->bScopeItem = TRUE;
  812. // This is a tree item, get the lUserParam.
  813. CNode* pNode = CNode::FromResultItem (pri);
  814. sc = ScCheckPointers(pNode, E_UNEXPECTED);
  815. if (sc)
  816. return sc.ToHr();
  817. // When the static node is visible in result-pane the result pane is
  818. // owned not by that static node's snapin so this is unexpected.
  819. if (pNode->IsStaticNode())
  820. return (sc = E_UNEXPECTED).ToHr();
  821. CMTNode* pMTNode = pNode->GetMTNode();
  822. sc = ScCheckPointers(pMTNode, E_UNEXPECTED);
  823. if (sc)
  824. return sc.ToHr();
  825. if (pMTNode->GetPrimaryComponentID() != id)
  826. return (sc = E_INVALIDARG).ToHr();
  827. if (RDI_PARAM & item->mask)
  828. item->lParam = pMTNode->GetUserParam();
  829. if (RDI_IMAGE & item->mask)
  830. item->nImage = pMTNode->GetImage();
  831. }
  832. item->itemID = CResultItem::ToHandle(pri);
  833. return sc.ToHr();
  834. }
  835. //+-------------------------------------------------------------------
  836. //
  837. // Member: CNodeInitObject::SetViewMode
  838. //
  839. // Synopsis: Change the ListView mode (detail...)
  840. //
  841. // Arguments: [nViewMode] - new mode.
  842. //
  843. // Returns: HRESULT
  844. //
  845. //--------------------------------------------------------------------
  846. STDMETHODIMP CNodeInitObject::SetViewMode(LONG nViewMode)
  847. {
  848. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::SetViewMode"));
  849. if (FALSE == (nViewMode >= 0 && nViewMode <= MMCLV_VIEWSTYLE_FILTERED))
  850. {
  851. sc = E_INVALIDARG;
  852. TraceSnapinError(_T("Invalid view mode"), sc);
  853. return sc.ToHr();
  854. }
  855. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  856. if (sc)
  857. return sc.ToHr();
  858. sc = m_spListViewPrivate->SetViewMode(nViewMode);
  859. return sc.ToHr();
  860. }
  861. //+-------------------------------------------------------------------
  862. //
  863. // Member: CNodeInitObject::Arrange
  864. //
  865. // Synopsis: Arrange the items is LV.
  866. //
  867. // Arguments: [style]
  868. //
  869. // Returns: HRESULT
  870. //
  871. //--------------------------------------------------------------------
  872. STDMETHODIMP CNodeInitObject::Arrange(long style)
  873. {
  874. DECLARE_SC(sc, _T("CNodeInitObject::Arrange"));
  875. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  876. if (sc)
  877. return sc.ToHr();
  878. sc = m_spListViewPrivate->Arrange(style);
  879. return sc.ToHr();
  880. }
  881. //+-------------------------------------------------------------------
  882. //
  883. // Member: CNodeInitObject::GetViewMode
  884. //
  885. // Synopsis: Get the current view mode.
  886. //
  887. // Arguments: [pnViewMode] - view mode [out]
  888. //
  889. // Returns: HRESULT
  890. //
  891. //--------------------------------------------------------------------
  892. STDMETHODIMP CNodeInitObject::GetViewMode(LONG * pnViewMode)
  893. {
  894. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::GetViewMode"));
  895. if (pnViewMode == MMCLV_NOPTR)
  896. {
  897. sc = E_INVALIDARG;
  898. TraceSnapinError(_T("NULL ViewMode pointer"), sc);
  899. return sc.ToHr();
  900. }
  901. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  902. if (sc)
  903. return sc.ToHr();
  904. *pnViewMode = m_spListViewPrivate->GetViewMode();
  905. return sc.ToHr();
  906. }
  907. //+-------------------------------------------------------------------
  908. //
  909. // Member: CNodeInitObject::ResetResultData
  910. //
  911. // Synopsis: Reset the result view.
  912. //
  913. // Arguments:
  914. //
  915. // Returns: HRESULT
  916. //
  917. //--------------------------------------------------------------------
  918. STDMETHODIMP CNodeInitObject::ResetResultData()
  919. {
  920. DECLARE_SC(sc, _T("CNodeInitObject::ResetResultData"));
  921. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  922. if (sc)
  923. return sc.ToHr();
  924. // Dont know what this assert means? (AnandhaG).
  925. ASSERT(TVOWNED_MAGICWORD == m_componentID);
  926. sc = m_spListViewPrivate->Reset();
  927. return sc.ToHr();
  928. }
  929. //+-------------------------------------------------------------------
  930. //
  931. // Member: CNodeInitObject::SetLoadMode
  932. //
  933. // Synopsis: Used for re-drawing LV/delay sorting.
  934. //
  935. // Note: If ListView setup (snapin is inserting columns/items,
  936. // MMC is applying column/view/sort settings) is going on
  937. // then delay sorting and also turn off drawing.
  938. //
  939. // Arguments:
  940. //
  941. // Returns: HRESULT
  942. //
  943. //--------------------------------------------------------------------
  944. STDMETHODIMP CNodeInitObject::SetLoadMode(BOOL bState)
  945. {
  946. DECLARE_SC(sc, _T("CNodeInitObject::SetLoadMode"));
  947. // Dont know what this assert means? (AnandhaG).
  948. ASSERT(TVOWNED_MAGICWORD == m_componentID);
  949. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  950. if (sc)
  951. return sc.ToHr();
  952. sc = m_spListViewPrivate->SetLoadMode(bState);
  953. return sc.ToHr();
  954. }
  955. //+-------------------------------------------------------------------
  956. //
  957. // Member: CNodeInitObject::SetDescBarText
  958. //
  959. // Synopsis: Set the desc bar text for ResultPane.
  960. //
  961. // Arguments: [pszDescText]
  962. //
  963. // Returns: HRESULT
  964. //
  965. //--------------------------------------------------------------------
  966. STDMETHODIMP CNodeInitObject::SetDescBarText(LPOLESTR pszDescText)
  967. {
  968. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::SetDescBarText"));
  969. CConsoleView* pConsoleView = GetConsoleView();
  970. sc = ScCheckPointers(pConsoleView, E_UNEXPECTED);
  971. if (sc)
  972. return sc.ToHr();
  973. // What happens if desc text is NULL?
  974. USES_CONVERSION;
  975. sc = pConsoleView->ScSetDescriptionBarText (W2T (pszDescText));
  976. return (sc.ToHr());
  977. }
  978. //+-------------------------------------------------------------------
  979. //
  980. // Member: CNodeInitObject::SetItemCount
  981. //
  982. // Synopsis: Set the number of items in Virtual List.
  983. //
  984. // Arguments: [nItemCount] - # items.
  985. // [dwOptions] - option flags.
  986. //
  987. // Returns: HRESULT
  988. //
  989. //--------------------------------------------------------------------
  990. STDMETHODIMP CNodeInitObject::SetItemCount(int nItemCount, DWORD dwOptions)
  991. {
  992. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IResultData::SetItemCount"));
  993. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  994. if (sc)
  995. return sc.ToHr();
  996. sc = m_spListViewPrivate->SetItemCount(nItemCount, dwOptions);
  997. return sc.ToHr();
  998. }
  999. /*+-------------------------------------------------------------------------*
  1000. *
  1001. * CNodeInitObject::RenameResultItem
  1002. *
  1003. * PURPOSE: Places the specified result item into rename mode.
  1004. *
  1005. * PARAMETERS:
  1006. * HRESULTITEM itemID :
  1007. *
  1008. * RETURNS:
  1009. * STDMETHODIMP
  1010. *
  1011. *+-------------------------------------------------------------------------*/
  1012. STDMETHODIMP
  1013. CNodeInitObject::RenameResultItem(HRESULTITEM itemID)
  1014. {
  1015. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, TEXT("IResultData2::RenameResultItem"));
  1016. sc = ScCheckPointers(m_spListViewPrivate, E_UNEXPECTED);
  1017. if (sc)
  1018. return sc.ToHr();
  1019. sc = m_spListViewPrivate->RenameItem(itemID);
  1020. if (sc)
  1021. return sc.ToHr();
  1022. return sc.ToHr();
  1023. }