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.

287 lines
9.4 KiB

  1. /*
  2. * @doc INTERNAL
  3. *
  4. * @module _DOC.H CTxtStory declaration |
  5. *
  6. * Purpose:
  7. * Encapsulate the plain-text document data (text blocks, cchText)
  8. *
  9. * Original Authors: <nl>
  10. * Christian Fortini <nl>
  11. * Murray Sargent <nl>
  12. *
  13. * History: <nl>
  14. * 6/25/95 alexgo commented and cleaned up
  15. *
  16. */
  17. #ifndef _DOC_H
  18. #define _DOC_H
  19. #include "_array.h"
  20. #define cbBlockCombine CbOfCch(3072)
  21. #define cbBlockMost CbOfCch(49152)
  22. #define cbBlockInitial CbOfCch(4096)
  23. #define cchGapInitial 128
  24. #define cchBlkCombmGapI (CchOfCb(cbBlockCombine) - cchGapInitial)
  25. #define cchBlkInitmGapI (CchOfCb(cbBlockInitial) - cchGapInitial)
  26. #define cchBlkInsertmGapI (CchOfCb(cbBlockInitial)*5 - cchGapInitial)
  27. class CDisplay;
  28. class CTxtPtr;
  29. class CTxtArray;
  30. /*
  31. * CTxtRun
  32. *
  33. * @class Formalizes a run of text. A range of text with same attribute,
  34. * (see CFmtDesc) or within the same line (see CLine), etc. Runs are kept
  35. * in arrays (see CArray) and are pointed to by CRunPtr's of various kinds.
  36. * In general the character position of a run is computed by summing the
  37. * length of all preceding runs, altho it may be possible to start from
  38. * some other cp, e.g., for CLines, from CDisplay::_cpFirstVisible.
  39. */
  40. class CTxtRun
  41. {
  42. //@access Public Methods and Data
  43. public:
  44. CTxtRun() {_cch = 0;} //@cmember Constructor
  45. LONG _cch; //@cmember Count of characters in run
  46. };
  47. /*
  48. * CTxtBlk
  49. *
  50. * @class A text block; a chunk of UNICODE text with a buffer gap to allow
  51. * for easy insertions and deletions.
  52. *
  53. * @base protected | CTxtRun
  54. *
  55. * @devnote A text block may have four states: <nl>
  56. * NULL: No data allocated for the block <nl>
  57. * <md CTxtBlk::_pch> == NULL <nl>
  58. * <md CTxtRun::_cch> == 0 <nl>
  59. * <md CTxtBlk::_ibGap> == 0 <nl>
  60. * <md CTxtBlk::_cbBlock> == 0 <nl>
  61. *
  62. * empty: All of the available space is a buffer gap <nl>
  63. * <md CTxtBlk::_pch> != NULL <nl>
  64. * <md CTxtRun::_cch> == 0 <nl>
  65. * <md CTxtBlk::_ibGap> == 0 <nl>
  66. * <md CTxtBlk::_cbBlock> <gt>= 0 <nl>
  67. *
  68. * normal: There is both data and a buffer gap <nl>
  69. * <md CTxtBlk::_pch> != NULL <nl>
  70. * <md CTxtRun::_cch> != 0 <nl>
  71. * <md CTxtBlk::_ibGap> != 0 <nl>
  72. * <md CTxtBlk::_cbBlock> <gt>= 0 <nl>
  73. *
  74. * full: The buffer gap is of zero size <nl>
  75. * <md CTxtBlk::_pch> != NULL <nl>
  76. * <md CTxtRun::_cch> <gt>= 0 <nl>
  77. * <md CTxtBlk::_ibGap> <gt> 0 <nl>
  78. * <md CTxtBlk::_cbBlock> == _cch * sizeof(WCHAR) <nl>
  79. *
  80. * The position of the buffer gap is given by _ibGap. With _cch and _cbBlock,
  81. * it's possible to figure out the *size* of the gap by simply calculating:
  82. * <nl>
  83. * size = _cbBlock - (_cch * sizeof(character))
  84. *
  85. */
  86. class CTxtBlk : public CTxtRun
  87. {
  88. friend class CTxtPtr;
  89. friend class CTxtArray;
  90. //@access Protected Methods
  91. protected:
  92. //@cmember Constructor
  93. CTxtBlk() {InitBlock(0);}
  94. //@cmember Destructor
  95. ~CTxtBlk() {FreeBlock();}
  96. //@cmember Initializes the block to the
  97. //# of bytes given by <p cb>
  98. BOOL InitBlock(LONG cb);
  99. //@cmember Sets a block to the NULL state
  100. VOID FreeBlock();
  101. //@cmember Moves the buffer gap in a
  102. //block
  103. VOID MoveGap(LONG ichGap);
  104. //@cmember Resizes a block to <p cbNew>
  105. //bytes
  106. BOOL ResizeBlock(LONG cbNew);
  107. //@access Private Data
  108. private:
  109. //@cmember Pointer to the text data
  110. WCHAR *_pch;
  111. //@cmember BYTE offset of the gap
  112. LONG _ibGap;
  113. //@cmember size of the block in bytes
  114. LONG _cbBlock;
  115. };
  116. /*
  117. * CTxtArray
  118. *
  119. * @class A dynamic array of <c CTxtBlk> classes
  120. *
  121. * @base public | CArray<lt>CTxtBlk<gt>
  122. */
  123. class CTxtArray : public CArray<CTxtBlk>
  124. {
  125. friend class CTxtPtr;
  126. friend class CTxtStory;
  127. //@access Public methods
  128. public:
  129. #ifdef DEBUG
  130. //@cmember Invariant support
  131. BOOL Invariant() const;
  132. #endif // DEBUG
  133. //@cmember Constructor
  134. CTxtArray();
  135. //@cmember Destructor
  136. ~CTxtArray();
  137. //@cmember Gets the total number of
  138. //characters in the array.
  139. LONG CalcTextLength() const;
  140. // Get access to cached CCharFormat and CParaFormat structures
  141. const CCharFormat* GetCharFormat(LONG iCF);
  142. const CParaFormat* GetParaFormat(LONG iPF);
  143. LONG Get_iCF() {return _iCF;}
  144. LONG Get_iPF() {return _iPF;}
  145. void Set_iCF(LONG iCF) {_iCF = (SHORT)iCF;}
  146. void Set_iPF(LONG iPF) {_iPF = (SHORT)iPF;}
  147. //@access Private methods
  148. private:
  149. //@cmember Adds cb blocks
  150. BOOL AddBlock(LONG itbNew, LONG cb);
  151. //@cmember Removes ctbDel blocks
  152. void RemoveBlocks(LONG itbFirst, LONG ctbDel);
  153. //@cmember Combines blocks adjacent to itb
  154. void CombineBlocks(LONG itb);
  155. //@cmember Splits a block
  156. BOOL SplitBlock(LONG itb, LONG ichSplit, LONG cchFirst,
  157. LONG cchLast, BOOL fStreaming);
  158. //@cmember Shrinks all blocks to minimal
  159. // size
  160. void ShrinkBlocks();
  161. //@cmember Copies chunk of text into
  162. // location given
  163. LONG GetChunk(TCHAR **ppch, LONG cch, TCHAR *pchChunk, LONG cchCopy) const;
  164. LONG _cchText; //@cmember Total text character count
  165. SHORT _iCF; //@cmember Default CCharFormat index
  166. SHORT _iPF;
  167. };
  168. class CBiDiLevel
  169. {
  170. public:
  171. BOOL operator == (const CBiDiLevel& level) const
  172. {
  173. return _value == level._value && _fStart == level._fStart;
  174. }
  175. BOOL operator != (const CBiDiLevel& level) const
  176. {
  177. return _value != level._value || _fStart != level._fStart;
  178. }
  179. BYTE _value; // embedding level (0..15)
  180. BYTE _fStart :1; // start a new level e.g. "{{abc}{123}}"
  181. };
  182. /*
  183. * CFormatRun
  184. *
  185. * @class A run of like formatted text, where the format is indicated by an
  186. * and index into a format table
  187. *
  188. * @base protected | CTxtRun
  189. */
  190. class CFormatRun : public CTxtRun
  191. {
  192. //@access Public Methods
  193. public:
  194. friend class CFormatRunPtr;
  195. friend class CTxtRange;
  196. friend class CRchTxtPtr;
  197. BOOL SameFormat(CFormatRun* pRun)
  198. {
  199. return _iFormat == pRun->_iFormat &&
  200. _level._value == pRun->_level._value &&
  201. _level._fStart == pRun->_level._fStart;
  202. }
  203. short _iFormat; //@cmember index of CHARFORMAT/PARAFORMAT struct
  204. CBiDiLevel _level; //@cmember BiDi level
  205. };
  206. //@type CFormatRuns | An array of CFormatRun classes
  207. typedef CArray<CFormatRun> CFormatRuns;
  208. /*
  209. * CTxtStory
  210. *
  211. * @class
  212. * The text "Document". Maintains the state information related to the
  213. * actual data of a document (such as text, formatting information, etc.)
  214. */
  215. class CTxtStory
  216. {
  217. friend class CTxtPtr;
  218. friend class CRchTxtPtr;
  219. friend class CReplaceFormattingAE;
  220. //@access Public Methods
  221. public:
  222. CTxtStory(); //@cmember Constructor
  223. ~CTxtStory(); //@cmember Destructor
  224. //@cmember Get total text length
  225. LONG GetTextLength() const
  226. {return _TxtArray._cchText;}
  227. //@cmember Get Paragraph Formatting runs
  228. CFormatRuns *GetPFRuns() {return _pPFRuns;}
  229. //@cmember Get Character Formatting runs
  230. CFormatRuns *GetCFRuns() {return _pCFRuns;}
  231. void DeleteFormatRuns(); //@cmember Converts to plain text from rich
  232. const CCharFormat* GetCharFormat(LONG iCF)
  233. {return _TxtArray.GetCharFormat(iCF);}
  234. const CParaFormat* GetParaFormat(LONG iPF)
  235. {return _TxtArray.GetParaFormat(iPF);}
  236. LONG Get_iCF() {return _TxtArray.Get_iCF();}
  237. LONG Get_iPF() {return _TxtArray.Get_iPF();}
  238. void Set_iCF(LONG iCF) {_TxtArray.Set_iCF(iCF);}
  239. void Set_iPF(LONG iPF) {_TxtArray.Set_iPF(iPF);}
  240. #ifdef DEBUG
  241. void DbgDumpStory(void); // Debug story dump member
  242. #endif
  243. //@access Private Data
  244. private:
  245. CTxtArray _TxtArray; //@cmember Plain-text runs
  246. CFormatRuns * _pCFRuns; //@cmember Ptr to Character-Formatting runs
  247. CFormatRuns * _pPFRuns; //@cmember Ptr to Paragraph-Formatting runs
  248. };
  249. #endif // ifndef _DOC_H