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.

158 lines
3.8 KiB

  1. //
  2. // candkey.cpp
  3. //
  4. #include "private.h"
  5. #include "candkey.h"
  6. /*============================================================================*/
  7. /* */
  8. /* C C A N D U I K E Y T A B L E */
  9. /* */
  10. /*============================================================================*/
  11. /* C C A N D U I K E Y T A B L E */
  12. /*------------------------------------------------------------------------------
  13. ------------------------------------------------------------------------------*/
  14. CCandUIKeyTable::CCandUIKeyTable( int nDataMax )
  15. {
  16. m_cRef = 1;
  17. m_pData = new CANDUIKEYDATA[ nDataMax ];
  18. m_nData = 0;
  19. m_nDataMax = nDataMax;
  20. }
  21. /* ~ C C A N D U I K E Y T A B L E */
  22. /*------------------------------------------------------------------------------
  23. ------------------------------------------------------------------------------*/
  24. CCandUIKeyTable::~CCandUIKeyTable( void )
  25. {
  26. delete m_pData;
  27. }
  28. /* Q U E R Y I N T E R F A C E */
  29. /*------------------------------------------------------------------------------
  30. Query interface
  31. (IUnknown method)
  32. ------------------------------------------------------------------------------*/
  33. STDAPI CCandUIKeyTable::QueryInterface( REFIID riid, void **ppvObj )
  34. {
  35. if (ppvObj == NULL) {
  36. return E_POINTER;
  37. }
  38. *ppvObj = NULL;
  39. if (IsEqualIID( riid, IID_IUnknown ) || IsEqualIID( riid, IID_ITfCandUIKeyTable )) {
  40. *ppvObj = SAFECAST( this, ITfCandUIKeyTable* );
  41. }
  42. if (*ppvObj == NULL) {
  43. return E_NOINTERFACE;
  44. }
  45. AddRef();
  46. return S_OK;
  47. }
  48. /* A D D R E F */
  49. /*------------------------------------------------------------------------------
  50. Increment reference count
  51. (IUnknown method)
  52. ------------------------------------------------------------------------------*/
  53. STDAPI_(ULONG) CCandUIKeyTable::AddRef( void )
  54. {
  55. m_cRef++;
  56. return m_cRef;
  57. }
  58. /* R E L E A S E */
  59. /*------------------------------------------------------------------------------
  60. Decrement reference count and release object
  61. (IUnknown method)
  62. ------------------------------------------------------------------------------*/
  63. STDAPI_(ULONG) CCandUIKeyTable::Release( void )
  64. {
  65. m_cRef--;
  66. if (0 < m_cRef) {
  67. return m_cRef;
  68. }
  69. delete this;
  70. return 0;
  71. }
  72. /* G E T K E Y D A T A N U M */
  73. /*------------------------------------------------------------------------------
  74. Get count of key data
  75. (ITfCandUIKeyTable method)
  76. ------------------------------------------------------------------------------*/
  77. HRESULT CCandUIKeyTable::GetKeyDataNum( int *piNum )
  78. {
  79. if (piNum == NULL) {
  80. return E_INVALIDARG;
  81. }
  82. *piNum = m_nData;
  83. return S_OK;
  84. }
  85. /* G E T K E Y D A T A */
  86. /*------------------------------------------------------------------------------
  87. Get key data
  88. (ITfCandUIKeyTable method)
  89. ------------------------------------------------------------------------------*/
  90. HRESULT CCandUIKeyTable::GetKeyData( int iData, CANDUIKEYDATA *pData )
  91. {
  92. *pData = m_pData[iData];
  93. return S_OK;
  94. }
  95. /* A D D K E Y D A T A */
  96. /*------------------------------------------------------------------------------
  97. ------------------------------------------------------------------------------*/
  98. HRESULT CCandUIKeyTable::AddKeyData(const CANDUIKEYDATA *pData)
  99. {
  100. if (m_nDataMax <= m_nData) {
  101. return E_FAIL;
  102. }
  103. if (pData == NULL) {
  104. Assert(FALSE);
  105. return E_INVALIDARG;
  106. }
  107. m_pData[ m_nData ] = *pData;
  108. m_nData++;
  109. return S_OK;
  110. }