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.

131 lines
2.9 KiB

  1. //
  2. // anchoref.h
  3. //
  4. // CAnchorRef
  5. //
  6. #ifndef ANCHOREF_H
  7. #define ANCHOREF_H
  8. #include "private.h"
  9. #include "memcache.h"
  10. #include "acp2anch.h"
  11. #include "anchor.h"
  12. class CAnchorList;
  13. extern const IID IID_PRIV_CANCHORREF;
  14. // work around for new #define in mem.h
  15. #undef new
  16. class CAnchorRef : public IAnchor
  17. {
  18. public:
  19. DECLARE_CACHED_NEW;
  20. CAnchorRef()
  21. {
  22. Dbg_MemSetThisNameIDCounter(TEXT("CAnchorRef"), PERF_ANCHORREF_COUNTER);
  23. _cRef = 1;
  24. Assert(_dwHistory == 0);
  25. Assert(_pa == NULL);
  26. }
  27. ~CAnchorRef()
  28. {
  29. CACPWrap *paw;
  30. if (_pa != NULL) // NULL means something went wrong in _Init
  31. {
  32. paw = _pa->_GetWrap(); // we must cache this because _pa could be deleted in Remove
  33. paw->_Remove(this);
  34. paw->_OnAnchorRelease();
  35. }
  36. }
  37. BOOL _Init(CACPWrap *paw, LONG ich, TsGravity gravity)
  38. {
  39. _fForwardGravity = (gravity == TS_GR_FORWARD ? 1 : 0);
  40. return (paw->_Insert(this, ich) == S_OK);
  41. }
  42. BOOL _Init(CACPWrap *paw, CAnchor *pa, TsGravity gravity)
  43. {
  44. _fForwardGravity = (gravity == TS_GR_FORWARD ? 1 : 0);
  45. return (paw->_Insert(this, pa) == S_OK);
  46. }
  47. static void _InitClass();
  48. static void _UninitClass();
  49. //
  50. // IUnknown methods
  51. //
  52. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  53. STDMETHODIMP_(ULONG) AddRef(void);
  54. STDMETHODIMP_(ULONG) Release(void);
  55. //
  56. // IAnchor
  57. //
  58. STDMETHODIMP SetGravity(TsGravity gravity);
  59. STDMETHODIMP GetGravity(TsGravity *pgravity);
  60. STDMETHODIMP IsEqual(IAnchor *paWith, BOOL *pfEqual);
  61. STDMETHODIMP Compare(IAnchor *paWith, LONG *plResult);
  62. STDMETHODIMP Shift(DWORD dwFlags, LONG cchReq, LONG *pcch, IAnchor *paHaltAnchor);
  63. STDMETHODIMP ShiftTo(IAnchor *paSite);
  64. STDMETHODIMP ShiftRegion(DWORD dwFlags, TsShiftDir dir, BOOL *pfNoRegion);
  65. STDMETHODIMP SetChangeHistoryMask(DWORD dwMask);
  66. STDMETHODIMP GetChangeHistory(DWORD *pdwHistory);
  67. STDMETHODIMP ClearChangeHistory();
  68. STDMETHODIMP Clone(IAnchor **ppaClone);
  69. LONG _GetACP()
  70. {
  71. _pa->_GetWrap()->_Dbg_AssertNoAppLock();
  72. return _pa->GetIch();
  73. }
  74. BOOL _SetACP(LONG acp);
  75. CAnchor *_GetAnchor()
  76. {
  77. return _pa;
  78. }
  79. CACPWrap *_GetWrap()
  80. {
  81. return _pa->_GetWrap();
  82. }
  83. private:
  84. friend CACPWrap;
  85. CAnchor *_pa;
  86. CAnchorRef *_prev;
  87. CAnchorRef *_next;
  88. LONG _cRef;
  89. DWORD _fForwardGravity : 1;
  90. DWORD _dwHistory : 2;
  91. DBG_ID_DECLARE;
  92. };
  93. // retore mem.h trick
  94. #ifdef DEBUG
  95. #define new new(TEXT(__FILE__), __LINE__)
  96. #endif // DEBUG
  97. // this call doesn't AddRef the object!
  98. inline CAnchorRef *GetCAnchorRef_NA(IAnchor *pa)
  99. {
  100. CAnchorRef *par;
  101. pa->QueryInterface(IID_PRIV_CANCHORREF, (void **)&par);
  102. return par;
  103. }
  104. #endif // ANCHOREF_H