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.

167 lines
3.5 KiB

  1. //
  2. // enumdim.cpp
  3. //
  4. #include "private.h"
  5. #include "enumic.h"
  6. #include "dim.h"
  7. #include "ic.h"
  8. DBG_ID_INSTANCE(CEnumInputContexts);
  9. //+---------------------------------------------------------------------------
  10. //
  11. // ctor
  12. //
  13. //----------------------------------------------------------------------------
  14. CEnumInputContexts::CEnumInputContexts()
  15. {
  16. Dbg_MemSetThisNameID(TEXT("CEnumInputContexts"));
  17. Assert(_rgContexts[0] == NULL);
  18. Assert(_rgContexts[1] == NULL);
  19. }
  20. //+---------------------------------------------------------------------------
  21. //
  22. // dtor
  23. //
  24. //----------------------------------------------------------------------------
  25. CEnumInputContexts::~CEnumInputContexts()
  26. {
  27. SafeRelease(_rgContexts[0]);
  28. SafeRelease(_rgContexts[1]);
  29. }
  30. //+---------------------------------------------------------------------------
  31. //
  32. // _Init
  33. //
  34. //----------------------------------------------------------------------------
  35. BOOL CEnumInputContexts::_Init(CDocumentInputManager *pdim)
  36. {
  37. int i;
  38. Assert(_iCur == 0);
  39. _iCount = pdim->_GetCurrentStack() + 1;
  40. for (i=0; i<_iCount; i++)
  41. {
  42. _rgContexts[i] = pdim->_GetIC(i);
  43. if (_rgContexts[i] == NULL)
  44. goto ExitError;
  45. _rgContexts[i]->AddRef();
  46. }
  47. return TRUE;
  48. ExitError:
  49. SafeRelease(_rgContexts[0]);
  50. Assert(_rgContexts[1] == NULL);
  51. return FALSE;
  52. }
  53. //+---------------------------------------------------------------------------
  54. //
  55. // Next
  56. //
  57. //----------------------------------------------------------------------------
  58. STDAPI CEnumInputContexts::Next(ULONG ulCount, ITfContext **ppic, ULONG *pcFetched)
  59. {
  60. ULONG cFetched = 0;
  61. if (pcFetched != NULL)
  62. {
  63. *pcFetched = 0;
  64. }
  65. if (ppic == NULL && ulCount > 0)
  66. return E_INVALIDARG;
  67. while (cFetched < ulCount)
  68. {
  69. if (_iCur >= _iCount)
  70. break;
  71. *ppic = _rgContexts[_iCur];
  72. (*ppic)->AddRef();
  73. ppic++;
  74. _iCur++;
  75. cFetched++;
  76. }
  77. if (pcFetched != NULL)
  78. {
  79. *pcFetched = cFetched;
  80. }
  81. return (cFetched == ulCount) ? S_OK : S_FALSE;
  82. }
  83. //+---------------------------------------------------------------------------
  84. //
  85. // Clone
  86. //
  87. //----------------------------------------------------------------------------
  88. STDAPI CEnumInputContexts::Clone(IEnumTfContexts **ppEnum)
  89. {
  90. CEnumInputContexts *ec;
  91. int i;
  92. ec = new CEnumInputContexts;
  93. if (ec == NULL)
  94. return E_OUTOFMEMORY;
  95. ec->_iCur = _iCur;
  96. ec->_iCount = _iCount;
  97. for (i=0; i<_iCount; i++)
  98. {
  99. ec->_rgContexts[i] = _rgContexts[i];
  100. ec->_rgContexts[i]->AddRef();
  101. }
  102. *ppEnum = ec;
  103. return S_OK;
  104. }
  105. //+---------------------------------------------------------------------------
  106. //
  107. // Reset
  108. //
  109. //----------------------------------------------------------------------------
  110. STDAPI CEnumInputContexts::Reset()
  111. {
  112. _iCur = 0;
  113. return S_OK;
  114. }
  115. //+---------------------------------------------------------------------------
  116. //
  117. // Skip
  118. //
  119. //----------------------------------------------------------------------------
  120. STDAPI CEnumInputContexts::Skip(ULONG ulCount)
  121. {
  122. // protect against overflow
  123. if (_iCur >= 2)
  124. return S_FALSE;
  125. ulCount = min(ulCount, 2);
  126. _iCur += ulCount;
  127. return (_iCur <= _iCount) ? S_OK : S_FALSE;
  128. }