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.

104 lines
2.6 KiB

  1. //
  2. // anchor.h
  3. //
  4. // CAnchor
  5. //
  6. #ifndef ANCHOR_H
  7. #define ANCHOR_H
  8. #include "private.h"
  9. #include "acp2anch.h"
  10. class CAnchorRef;
  11. class CACPWrap;
  12. class CAnchor
  13. {
  14. public:
  15. CAnchor()
  16. {
  17. Dbg_MemSetThisNameIDCounter(TEXT("CAnchor"), PERF_ANCHOR_COUNTER);
  18. Assert(_fNormalized == FALSE);
  19. }
  20. CACPWrap *_GetWrap()
  21. {
  22. return _paw;
  23. }
  24. BOOL _InsidePendingRange()
  25. {
  26. LONG ichDeltaStart;
  27. // if there's no pending delta range, we're not inside one
  28. if (!_paw->_IsPendingDelta())
  29. return FALSE;
  30. ichDeltaStart = _paw->_GetPendingDeltaAnchor()->_ich;
  31. // if the pending delta is negative, all anchor ich's are ascending
  32. if (_paw->_GetPendingDelta() < 0)
  33. return (_ich >= ichDeltaStart);
  34. // otherwise, there maybe overlapping anchor ichs like
  35. // 1, 3, 6 (delta start) 1, 3, 6, 10, ..
  36. //
  37. // so we can't always just test vs. ichDeltaStart.
  38. // we know the delta is positive, so an _ich less then the start ich
  39. // must not be in the pending range
  40. if (_ich < ichDeltaStart)
  41. return FALSE;
  42. // similarly, an ich >= ichDeltaStart + delta must be inside the range
  43. if (_ich >= ichDeltaStart + _paw->_GetPendingDelta())
  44. return TRUE;
  45. // if the ich matches the start of the pending delta, we can test vs.
  46. // the delta start anchor
  47. if (_ich == ichDeltaStart)
  48. return _paw->_GetPendingDeltaAnchor() == this;
  49. // if we get here, there's no way to tell just looking at this anchor
  50. // whether or not it's in the pending range -- its ich is legal
  51. // either way. We have to bite the bullet and find its index in the
  52. // anchor array.
  53. return (_paw->_FindWithinPendingRange(_ich) == this);
  54. }
  55. int GetIch()
  56. {
  57. return (_InsidePendingRange() ? _ich + _paw->_GetPendingDelta() : _ich);
  58. }
  59. void SetACP(int ich) // careful, this method is very dangerous
  60. {
  61. Assert(ich >= 0);
  62. if (_InsidePendingRange())
  63. {
  64. _ich = ich - _paw->_GetPendingDelta();
  65. }
  66. else
  67. {
  68. _ich = ich;
  69. }
  70. }
  71. BOOL IsNormalized()
  72. {
  73. return _fNormalized;
  74. }
  75. private:
  76. friend CACPWrap;
  77. CACPWrap *_paw;
  78. int _ich; // offset of this anchor in the text stream, dangerous to change directly!
  79. CAnchorRef *_parFirst; // list of ranges referencing this anchor
  80. BOOL _fNormalized : 1;
  81. DBG_ID_DECLARE;
  82. };
  83. #endif // ANCHOR_H