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.

186 lines
4.7 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. public:
  62. CFixArrayBase (LONG cbElem);
  63. ~CFixArrayBase () {Free();}
  64. void* Elem(LONG iel) const {return _prgel + iel * _cbElem;}
  65. LONG Count() const {return _cel;}
  66. LONG Add ();
  67. void Free (LONG ielFirst);
  68. void Free ();
  69. HRESULT Deref (LONG iel, const void **ppel) const;
  70. LONG AddRef (LONG iel);
  71. LONG Release(LONG iel);
  72. HRESULT Cache (const void *pel, LONG *piel);
  73. #ifdef DEBUG
  74. void CheckFreeChainFn(LPSTR szFile, INT nLine);
  75. #endif
  76. protected:
  77. LONG & RefCount(LONG iel);
  78. private:
  79. LONG Find (const void *pel);
  80. };
  81. template <class ELEM>
  82. class CFixArray : public CFixArrayBase
  83. {
  84. public:
  85. CFixArray () : CFixArrayBase (sizeof(ELEM)) {}
  86. //@cmember Get ptr to <p iel>'th
  87. ELEM * Elem(LONG iel) const // element
  88. {return (ELEM *)CFixArrayBase::Elem(iel);}
  89. protected: //@cmember Get ptr to <p iel>'th
  90. LONG & RefCount(LONG iel) // ref count
  91. {return CFixArrayBase::RefCount(iel);}
  92. };
  93. #ifdef DEBUG
  94. #define CheckFreeChain()\
  95. CheckFreeChainFn(__FILE__, __LINE__)
  96. #else
  97. #define CheckFreeChain()
  98. #endif // DEBUG
  99. //================================ CCharFormatArray ==============================
  100. class CCharFormatArray : public CFixArray<CCharFormat>, public ICharFormatCache
  101. {
  102. protected:
  103. LONG Find(const CCharFormat *pCF);
  104. public:
  105. CCharFormatArray() : CFixArray<CCharFormat>() {}
  106. // ICharFormatCache
  107. virtual HRESULT Cache(const CCharFormat *pCF, LONG *piCF);
  108. virtual HRESULT Deref(LONG iCF, const CCharFormat **ppCF) const;
  109. virtual LONG AddRef(LONG iCF);
  110. virtual LONG Release(LONG iCF);
  111. virtual void Destroy();
  112. };
  113. //=============================== CParaFormatArray ==================================
  114. class CParaFormatArray : public CFixArray<CParaFormat>, public IParaFormatCache
  115. {
  116. protected:
  117. LONG Find(const CParaFormat *pPF);
  118. public:
  119. CParaFormatArray() : CFixArray<CParaFormat>() {}
  120. // IParaFormatCache
  121. virtual HRESULT Cache(const CParaFormat *pPF, LONG *piPF);
  122. virtual HRESULT Deref(LONG iPF, const CParaFormat **ppPF) const;
  123. virtual LONG AddRef(LONG iPF);
  124. virtual LONG Release(LONG iPF);
  125. virtual void Destroy();
  126. };
  127. //=============================== CTabsArray ==================================
  128. class CTabsArray : public CFixArray<CTabs>
  129. {
  130. protected:
  131. LONG Find(const LONG *prgxTabs, LONG cTab);
  132. public:
  133. CTabsArray() : CFixArray<CTabs>() {}
  134. ~CTabsArray();
  135. LONG Cache(const LONG *prgxTabs, LONG cTab);
  136. const LONG *Deref(LONG iTabs) const;
  137. LONG AddRef (LONG iTabs);
  138. LONG Release(LONG iTabs);
  139. };
  140. // Access to the format caches
  141. ICharFormatCache *GetCharFormatCache();
  142. IParaFormatCache *GetParaFormatCache();
  143. CTabsArray *GetTabsCache();
  144. #endif