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.

264 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. prdcol.cpp
  5. Abstract:
  6. Product collection object implementation.
  7. Author:
  8. Don Ryan (donryan) 11-Jan-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "llsmgr.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char BASED_CODE THIS_FILE[] = __FILE__;
  18. #endif
  19. IMPLEMENT_DYNCREATE(CProducts, CCmdTarget)
  20. BEGIN_MESSAGE_MAP(CProducts, CCmdTarget)
  21. //{{AFX_MSG_MAP(CProducts)
  22. // NOTE - the ClassWizard will add and remove mapping macros here.
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. BEGIN_DISPATCH_MAP(CProducts, CCmdTarget)
  26. //{{AFX_DISPATCH_MAP(CProducts)
  27. DISP_PROPERTY_EX(CProducts, "Application", GetApplication, SetNotSupported, VT_DISPATCH)
  28. DISP_PROPERTY_EX(CProducts, "Parent", GetParent, SetNotSupported, VT_DISPATCH)
  29. DISP_PROPERTY_EX(CProducts, "Count", GetCount, SetNotSupported, VT_I4)
  30. DISP_FUNCTION(CProducts, "Item", GetItem, VT_DISPATCH, VTS_VARIANT)
  31. //}}AFX_DISPATCH_MAP
  32. END_DISPATCH_MAP()
  33. CProducts::CProducts(CCmdTarget* pParent, CObArray* pObArray)
  34. /*++
  35. Routine Description:
  36. Constructor for product collection object.
  37. Arguments:
  38. pParent - creator of object.
  39. pObArray - object list to enumerate.
  40. Return Values:
  41. None.
  42. --*/
  43. {
  44. EnableAutomation();
  45. #ifdef ENABLE_PARENT_CHECK
  46. ASSERT(pParent && pParent->IsKindOf(RUNTIME_CLASS(CController)));
  47. #endif // ENABLE_PARENT_CHECK
  48. ASSERT_VALID(pObArray);
  49. m_pParent = pParent;
  50. m_pObArray = pObArray;
  51. }
  52. CProducts::~CProducts()
  53. /*++
  54. Routine Description:
  55. Destructor for product collection object.
  56. Arguments:
  57. None.
  58. Return Values:
  59. None.
  60. --*/
  61. {
  62. //
  63. // Nothing to do here.
  64. //
  65. }
  66. void CProducts::OnFinalRelease()
  67. /*++
  68. Routine Description:
  69. When the last reference for an automation object is released
  70. OnFinalRelease is called. This implementation deletes object.
  71. Arguments:
  72. None.
  73. Return Values:
  74. None.
  75. --*/
  76. {
  77. delete this;
  78. }
  79. LPDISPATCH CProducts::GetApplication()
  80. /*++
  81. Routine Description:
  82. Returns the application object.
  83. Arguments:
  84. None.
  85. Return Values:
  86. VT_DISPATCH.
  87. --*/
  88. {
  89. return theApp.GetAppIDispatch();
  90. }
  91. long CProducts::GetCount()
  92. /*++
  93. Routine Description:
  94. Returns number of items in collection.
  95. Arguments:
  96. None.
  97. Return Values:
  98. VT_I4.
  99. --*/
  100. {
  101. ASSERT_VALID(m_pObArray);
  102. return (long)m_pObArray->GetSize();
  103. }
  104. LPDISPATCH CProducts::GetItem(const VARIANT FAR& index)
  105. /*++
  106. Routine Description:
  107. Retrieves specified product object from collection.
  108. Arguments:
  109. index - optional argument that may be a string (VT_BSTR)
  110. indicating the product name or a number (VT_I4) indicating
  111. the position within collection.
  112. Return Values:
  113. VT_DISPATCH or VT_EMPTY.
  114. --*/
  115. {
  116. ASSERT_VALID(m_pObArray);
  117. LPDISPATCH lpdispatch = NULL;
  118. CProduct* pProduct;
  119. INT_PTR iProduct;
  120. VARIANT vProduct;
  121. VariantInit(&vProduct);
  122. if (iProduct = m_pObArray->GetSize())
  123. {
  124. if (index.vt == VT_BSTR)
  125. {
  126. while (iProduct--)
  127. {
  128. if (pProduct = (CProduct*)m_pObArray->GetAt(iProduct))
  129. {
  130. ASSERT(pProduct->IsKindOf(RUNTIME_CLASS(CProduct)));
  131. if (!pProduct->m_strName.CompareNoCase(index.bstrVal))
  132. {
  133. lpdispatch = pProduct->GetIDispatch(TRUE);
  134. break;
  135. }
  136. }
  137. }
  138. }
  139. else if (SUCCEEDED(VariantChangeType(&vProduct, (VARIANT FAR *)&index, 0, VT_I4)))
  140. {
  141. if (((int)vProduct.lVal >= 0) && ((int)vProduct.lVal < iProduct))
  142. {
  143. if (pProduct = (CProduct*)m_pObArray->GetAt((int)vProduct.lVal))
  144. {
  145. ASSERT(pProduct->IsKindOf(RUNTIME_CLASS(CProduct)));
  146. lpdispatch = pProduct->GetIDispatch(TRUE);
  147. }
  148. }
  149. }
  150. }
  151. return lpdispatch;
  152. }
  153. LPDISPATCH CProducts::GetParent()
  154. /*++
  155. Routine Description:
  156. Returns the parent of the object.
  157. Arguments:
  158. None.
  159. Return Values:
  160. VT_DISPATCH.
  161. --*/
  162. {
  163. return m_pParent ? m_pParent->GetIDispatch(TRUE) : NULL;
  164. }