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.

120 lines
2.9 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: nmutil.cpp
  7. *
  8. * Contents:
  9. *
  10. * History:
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #include "stdafx.h"
  14. #include "nmutil.h"
  15. #include "rsltitem.h"
  16. COMPONENTID GetComponentID (CNode* pNode, CResultItem* pri /* =0 */)
  17. {
  18. ASSERT(pNode != NULL || ((pri != NULL) && (pri->IsScopeItem())));
  19. CNode* pNodeContext = pNode;
  20. if ((pri != NULL) && pri->IsScopeItem())
  21. pNodeContext = CNode::FromResultItem (pri);
  22. ASSERT(pNodeContext != NULL);
  23. ASSERT(pNodeContext->IsInitialized() == TRUE);
  24. ASSERT(pNodeContext->GetPrimaryComponent() != NULL);
  25. return pNodeContext->GetPrimaryComponent()->GetComponentID();
  26. }
  27. CComponent* GetComponent (CNode* pNode, CResultItem* pri /* =0 */)
  28. {
  29. ASSERT(pNode != NULL);
  30. if (pri != NULL)
  31. {
  32. if (pri->IsScopeItem())
  33. {
  34. CNode* pNode = CNode::FromResultItem (pri);
  35. if (pNode == NULL)
  36. return (NULL);
  37. if (pNode->IsInitialized() == FALSE)
  38. {
  39. HRESULT hr = pNode->InitComponents();
  40. if (FAILED(hr))
  41. return NULL;
  42. }
  43. return pNode->GetPrimaryComponent();
  44. }
  45. else
  46. {
  47. return pNode->GetComponent (pri->GetOwnerID());
  48. }
  49. }
  50. return pNode->GetPrimaryComponent();
  51. }
  52. void GetComponentsForMultiSel (CNode* pNode, CComponentPtrArray& rgComps)
  53. {
  54. ASSERT(pNode != NULL);
  55. ASSERT(pNode->GetViewData() != NULL);
  56. ASSERT(rgComps.GetSize() == 0);
  57. HWND hwnd = pNode->GetViewData()->GetListCtrl();
  58. BOOL bVirtual = pNode->GetViewData()->IsVirtualList();
  59. ASSERT(hwnd != NULL);
  60. ASSERT(::IsWindow(hwnd));
  61. int iNext = ListView_GetNextItem(hwnd, -1, LVNI_SELECTED);
  62. CComponent* pCC;
  63. long lData;
  64. if (bVirtual)
  65. {
  66. pCC = pNode->GetPrimaryComponent();
  67. }
  68. else
  69. {
  70. lData = ListView_GetItemData(hwnd, iNext);
  71. ASSERT(lData != 0);
  72. pCC = ::GetComponent(pNode, CResultItem::FromHandle (lData));
  73. }
  74. if (pCC == NULL)
  75. {
  76. rgComps.RemoveAll();
  77. return;
  78. }
  79. rgComps.AddComponent(pCC);
  80. // if virtual list, all items are from the same component
  81. if (bVirtual)
  82. return;
  83. while ((iNext = ListView_GetNextItem(hwnd, iNext, LVNI_SELECTED)) != -1)
  84. {
  85. lData = ListView_GetItemData(hwnd, iNext);
  86. ASSERT(lData != 0);
  87. CComponent* pCCTemp = GetComponent(pNode, CResultItem::FromHandle (lData));
  88. if (pCCTemp == NULL)
  89. {
  90. rgComps.RemoveAll();
  91. return;
  92. }
  93. if (pCCTemp != pCC)
  94. rgComps.AddComponent(pCCTemp);
  95. }
  96. }