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.

159 lines
3.9 KiB

  1. //---------------------------------------------------------------------------
  2. // Bookmark.cpp : CVDBookmark implementation
  3. //
  4. // Copyright (c) 1996 Microsoft Corporation, All Rights Reserved
  5. // Developed by Sheridan Software Systems, Inc.
  6. //---------------------------------------------------------------------------
  7. #include "stdafx.h"
  8. #include "bookmark.h"
  9. SZTHISFILE
  10. //=--------------------------------------------------------------------------=
  11. // CVDBookmark - Constructor
  12. //
  13. CVDBookmark::CVDBookmark()
  14. {
  15. VariantInit((VARIANT*)&m_varBookmark);
  16. m_pBookmark = NULL;
  17. Reset();
  18. }
  19. //=--------------------------------------------------------------------------=
  20. // ~CVDBookmark - Destructor
  21. //
  22. CVDBookmark::~CVDBookmark()
  23. {
  24. SAFEARRAY * psa = NULL;
  25. if ((VT_ARRAY | VT_UI1) == V_VT(&m_varBookmark))
  26. psa = V_ARRAY(&m_varBookmark);
  27. if (psa && m_pBookmark)
  28. SafeArrayUnaccessData(psa);
  29. VariantClear((VARIANT*)&m_varBookmark);
  30. }
  31. //=--------------------------------------------------------------------------=
  32. // Reset
  33. //
  34. void CVDBookmark::Reset()
  35. {
  36. m_cbBookmark = 0;
  37. m_hRow = 0;
  38. SetBookmark(VDBOOKMARKSTATUS_BEGINNING);
  39. }
  40. //=--------------------------------------------------------------------------=
  41. // SetBookmark
  42. //
  43. HRESULT CVDBookmark::SetBookmark(WORD wStatus, HROW hRow, BYTE* pBookmark, ULONG cbBookmark)
  44. {
  45. SAFEARRAY * psa = NULL;
  46. switch (wStatus)
  47. {
  48. case VDBOOKMARKSTATUS_BEGINNING:
  49. cbBookmark = CURSOR_DB_BMK_SIZE;
  50. pBookmark = (BYTE*)&CURSOR_DBBMK_BEGINNING;
  51. break;
  52. case VDBOOKMARKSTATUS_END:
  53. cbBookmark = CURSOR_DB_BMK_SIZE;
  54. pBookmark = (BYTE*)&CURSOR_DBBMK_END;
  55. break;
  56. case VDBOOKMARKSTATUS_CURRENT:
  57. break;
  58. case VDBOOKMARKSTATUS_INVALID:
  59. return S_OK;
  60. default:
  61. ASSERT_(FALSE);
  62. return E_FAIL;
  63. }
  64. // initialize status flag
  65. m_wStatus = VDBOOKMARKSTATUS_INVALID;
  66. // get pointer to existing safe array
  67. if ((VT_ARRAY | VT_UI1) == V_VT(&m_varBookmark))
  68. psa = V_ARRAY(&m_varBookmark);
  69. if (psa)
  70. {
  71. // if len changed and new len not = zero then redim array
  72. if (cbBookmark && cbBookmark != m_cbBookmark)
  73. {
  74. long lUbound;
  75. HRESULT hr = SafeArrayGetUBound(psa, 1, &lUbound);
  76. ASSERT_(!hr);
  77. if ((ULONG)lUbound + 1 != cbBookmark) // confirm array needs rediming
  78. {
  79. if (psa && m_pBookmark)
  80. SafeArrayUnaccessData(psa); // release old lock
  81. SAFEARRAYBOUND sab;
  82. sab.lLbound = 0;
  83. sab.cElements = cbBookmark;
  84. hr = SafeArrayRedim(psa, &sab);
  85. ASSERT_(!hr);
  86. if SUCCEEDED(hr)
  87. SafeArrayAccessData(psa, (void**)&m_pBookmark);
  88. else
  89. return hr;
  90. }
  91. }
  92. }
  93. else
  94. // if no existing array create one if passed in length not zero
  95. if (cbBookmark && pBookmark)
  96. {
  97. SAFEARRAYBOUND sab;
  98. sab.lLbound = 0;
  99. sab.cElements = cbBookmark;
  100. psa = SafeArrayCreate(VT_UI1, 1, &sab);
  101. // if create was successful intital VARIANT structure
  102. if (psa)
  103. {
  104. V_VT(&m_varBookmark) = VT_ARRAY | VT_UI1;
  105. V_ARRAY(&m_varBookmark) = psa;
  106. SafeArrayAccessData(psa, (void**)&m_pBookmark);
  107. }
  108. else
  109. return E_OUTOFMEMORY;
  110. }
  111. // if everthing ok then copy bookmark data into safe array
  112. if (psa && m_pBookmark && pBookmark && cbBookmark)
  113. memcpy(m_pBookmark, pBookmark, cbBookmark);
  114. m_wStatus = wStatus;
  115. m_cbBookmark = cbBookmark;
  116. m_hRow = hRow;
  117. return S_OK;
  118. }
  119. //=--------------------------------------------------------------------------=
  120. // IsSameBookmark - compares bookmark data
  121. //
  122. BOOL CVDBookmark::IsSameBookmark(CVDBookmark * pbm)
  123. {
  124. ASSERT_(pbm);
  125. if (!pbm ||
  126. VDBOOKMARKSTATUS_INVALID == pbm->GetStatus() ||
  127. VDBOOKMARKSTATUS_INVALID == m_wStatus)
  128. return FALSE;
  129. if (pbm->GetBookmarkLen() == m_cbBookmark &&
  130. memcmp(pbm->GetBookmark(), m_pBookmark, m_cbBookmark) == 0)
  131. return TRUE;
  132. else
  133. return FALSE;
  134. }