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.

185 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. enum.cpp
  5. Abstract:
  6. This file implements the IEnumInputContext Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "enum.h"
  13. //+---------------------------------------------------------------------------
  14. //
  15. // QueryInterface
  16. //
  17. //----------------------------------------------------------------------------
  18. HRESULT
  19. CEnumInputContext::QueryInterface(
  20. REFIID riid,
  21. void **ppvObj
  22. )
  23. {
  24. if (ppvObj == NULL)
  25. return E_INVALIDARG;
  26. *ppvObj = NULL;
  27. if (IsEqualIID(riid, IID_IUnknown) ||
  28. IsEqualIID(riid, IID_IEnumInputContext))
  29. {
  30. *ppvObj = SAFECAST(this, IEnumInputContext *);
  31. }
  32. if (*ppvObj)
  33. {
  34. AddRef();
  35. return S_OK;
  36. }
  37. return E_NOINTERFACE;
  38. }
  39. //+---------------------------------------------------------------------------
  40. //
  41. // AddRef
  42. //
  43. //----------------------------------------------------------------------------
  44. ULONG
  45. CEnumInputContext::AddRef()
  46. {
  47. return ++_cRef;
  48. }
  49. //+---------------------------------------------------------------------------
  50. //
  51. // Release
  52. //
  53. //----------------------------------------------------------------------------
  54. ULONG
  55. CEnumInputContext::Release()
  56. {
  57. LONG cr = --_cRef;
  58. Assert(_cRef >= 0);
  59. if (_cRef == 0)
  60. {
  61. delete this;
  62. }
  63. return cr;
  64. }
  65. //+---------------------------------------------------------------------------
  66. //
  67. // Clone
  68. //
  69. //----------------------------------------------------------------------------
  70. HRESULT
  71. CEnumInputContext::Clone(
  72. IEnumInputContext** ppEnum
  73. )
  74. {
  75. if (ppEnum == NULL)
  76. return E_INVALIDARG;
  77. *ppEnum = NULL;
  78. CEnumInputContext* pClone;
  79. if ((pClone = new CEnumInputContext(_list)) == NULL)
  80. return E_OUTOFMEMORY;
  81. *ppEnum = pClone;
  82. return S_OK;
  83. }
  84. //+---------------------------------------------------------------------------
  85. //
  86. // Next
  87. //
  88. //----------------------------------------------------------------------------
  89. HRESULT
  90. CEnumInputContext::Next(
  91. ULONG ulCount,
  92. HIMC* rgInputContext,
  93. ULONG* pcFetched
  94. )
  95. {
  96. if (rgInputContext == NULL)
  97. return E_INVALIDARG;
  98. ULONG cFetched;
  99. if (pcFetched == NULL)
  100. pcFetched = &cFetched;
  101. if (_pos == NULL) {
  102. *pcFetched = 0;
  103. return S_FALSE;
  104. }
  105. for (*pcFetched = 0; *pcFetched < ulCount; *pcFetched++, rgInputContext++) {
  106. _list.GetNextHimc(_pos, rgInputContext);
  107. if (_pos == NULL)
  108. break;
  109. }
  110. return S_OK;
  111. }
  112. //+---------------------------------------------------------------------------
  113. //
  114. // Reset
  115. //
  116. //----------------------------------------------------------------------------
  117. HRESULT
  118. CEnumInputContext::Reset(
  119. )
  120. {
  121. _pos = _list.GetStartPosition();
  122. return S_OK;
  123. }
  124. //+---------------------------------------------------------------------------
  125. //
  126. // Skip
  127. //
  128. //----------------------------------------------------------------------------
  129. HRESULT
  130. CEnumInputContext::Skip(
  131. ULONG ulCount
  132. )
  133. {
  134. POSITION backup = _pos;
  135. while (ulCount--) {
  136. HIMC imc;
  137. _list.GetNextHimc(_pos, &imc);
  138. if (_pos == NULL) {
  139. _pos = backup;
  140. return S_FALSE;
  141. }
  142. }
  143. return S_OK;
  144. }