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.

192 lines
4.8 KiB

  1. /*
  2. * _FORMAT.H
  3. *
  4. * Purpose:
  5. * CCharFormatArray and CParaFormatArray
  6. *
  7. * Authors:
  8. * Original RichEdit code: David R. Fulmer
  9. * Christian Fortini
  10. * Murray Sargent
  11. *
  12. * Copyright (c) 1995-1997, Microsoft Corporation. All rights reserved.
  13. */
  14. #ifndef _FORMAT_H
  15. #define _FORMAT_H
  16. #include "textserv.h"
  17. #define celGrow 8
  18. #define FLBIT 0x80000000
  19. //+-----------------------------------------------------------------------
  20. // Interface IFormatCache
  21. // Interface ICharFormatCache
  22. // Interface IParaFormatCache
  23. //
  24. // Format caches - Used by the host to manage the cache of CHARFORMAT
  25. // and PARAFORMAT structures. Note that these interfaces DON'T derive from
  26. // IUnknown
  27. //------------------------------------------------------------------------
  28. interface IFormatCache
  29. {
  30. virtual LONG AddRef(LONG iFormat) = 0;
  31. virtual LONG Release(LONG iFormat) = 0;
  32. virtual void Destroy() = 0;
  33. };
  34. template <class FORMAT>
  35. interface ITextFormatCache : public IFormatCache
  36. {
  37. virtual HRESULT Cache(const FORMAT *pFormat, LONG *piFormat) = 0;
  38. virtual HRESULT Deref(LONG iFormat, const FORMAT **ppFormat) const = 0;
  39. };
  40. interface ICharFormatCache : public ITextFormatCache<CCharFormat>
  41. {
  42. };
  43. interface IParaFormatCache : public ITextFormatCache<CParaFormat>
  44. {
  45. };
  46. void ReleaseFormats(LONG iCF, LONG iPF);
  47. HRESULT CreateFormatCaches();
  48. HRESULT DestroyFormatCaches();
  49. // =========================== CFixArray =================================
  50. // This array class ensures stability of the indexes. Elements are freed by
  51. // inserting them in a free list, and the array is never shrunk.
  52. // The first UINT of ELEM is used to store the index of next element in the
  53. // free list.
  54. class CFixArrayBase
  55. {
  56. private:
  57. char* _prgel; // array of elements
  58. LONG _cel; // total count of elements (including free ones)
  59. LONG _ielFirstFree; // - first free element
  60. LONG _cbElem; // size of each element
  61. #ifdef _WIN64
  62. LONG _cbPad; // use in Win64 to make sure each element + RefCount is
  63. // 64 bit aligned.
  64. #else
  65. #define _cbPad 0
  66. #endif
  67. public:
  68. CFixArrayBase (LONG cbElem);
  69. ~CFixArrayBase () {Free();}
  70. void* Elem(LONG iel) const {return _prgel + iel * _cbElem;}
  71. LONG Count() const {return _cel;}
  72. LONG Add ();
  73. void Free (LONG ielFirst);
  74. void Free ();
  75. HRESULT Deref (LONG iel, const void **ppel) const;
  76. LONG AddRef (LONG iel);
  77. LONG Release(LONG iel);
  78. HRESULT Cache (const void *pel, LONG *piel);
  79. #ifdef DEBUG
  80. void CheckFreeChainFn(LPSTR szFile, INT nLine);
  81. #endif
  82. protected:
  83. LONG & RefCount(LONG iel);
  84. private:
  85. LONG Find (const void *pel);
  86. };
  87. template <class ELEM>
  88. class CFixArray : public CFixArrayBase
  89. {
  90. public:
  91. CFixArray () : CFixArrayBase (sizeof(ELEM)) {}
  92. //@cmember Get ptr to <p iel>'th
  93. ELEM * Elem(LONG iel) const // element
  94. {return (ELEM *)CFixArrayBase::Elem(iel);}
  95. protected: //@cmember Get ptr to <p iel>'th
  96. LONG & RefCount(LONG iel) // ref count
  97. {return CFixArrayBase::RefCount(iel);}
  98. };
  99. #ifdef DEBUG
  100. #define CheckFreeChain()\
  101. CheckFreeChainFn(__FILE__, __LINE__)
  102. #else
  103. #define CheckFreeChain()
  104. #endif // DEBUG
  105. //================================ CCharFormatArray ==============================
  106. class CCharFormatArray : public CFixArray<CCharFormat>, public ICharFormatCache
  107. {
  108. protected:
  109. LONG Find(const CCharFormat *pCF);
  110. public:
  111. CCharFormatArray() : CFixArray<CCharFormat>() {}
  112. // ICharFormatCache
  113. virtual HRESULT Cache(const CCharFormat *pCF, LONG *piCF);
  114. virtual HRESULT Deref(LONG iCF, const CCharFormat **ppCF) const;
  115. virtual LONG AddRef(LONG iCF);
  116. virtual LONG Release(LONG iCF);
  117. virtual void Destroy();
  118. };
  119. //=============================== CParaFormatArray ==================================
  120. class CParaFormatArray : public CFixArray<CParaFormat>, public IParaFormatCache
  121. {
  122. protected:
  123. LONG Find(const CParaFormat *pPF);
  124. public:
  125. CParaFormatArray() : CFixArray<CParaFormat>() {}
  126. // IParaFormatCache
  127. virtual HRESULT Cache(const CParaFormat *pPF, LONG *piPF);
  128. virtual HRESULT Deref(LONG iPF, const CParaFormat **ppPF) const;
  129. virtual LONG AddRef(LONG iPF);
  130. virtual LONG Release(LONG iPF);
  131. virtual void Destroy();
  132. };
  133. //=============================== CTabsArray ==================================
  134. class CTabsArray : public CFixArray<CTabs>
  135. {
  136. protected:
  137. LONG Find(const LONG *prgxTabs, LONG cTab);
  138. public:
  139. CTabsArray() : CFixArray<CTabs>() {}
  140. ~CTabsArray();
  141. LONG Cache(const LONG *prgxTabs, LONG cTab);
  142. const LONG *Deref(LONG iTabs) const;
  143. LONG AddRef (LONG iTabs);
  144. LONG Release(LONG iTabs);
  145. };
  146. // Access to the format caches
  147. ICharFormatCache *GetCharFormatCache();
  148. IParaFormatCache *GetParaFormatCache();
  149. CTabsArray *GetTabsCache();
  150. #endif