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.

248 lines
9.3 KiB

  1. /*
  2. * @doc INTERNAL
  3. *
  4. * @module _TEXT.H -- Declaration for a CTxtRun pointer |
  5. *
  6. * CTxtRun pointers point at the plain text runs (CTxtArray) of the
  7. * backing store and derive from CRunPtrBase via the CRunPtr template.
  8. *
  9. * Copyright (c) 1995-2000, Microsoft Corporation. All rights reserved.
  10. */
  11. #ifndef _TEXT_H
  12. #define _TEXT_H
  13. #include "_runptr.h"
  14. #include "_doc.h"
  15. #include "textserv.h"
  16. #include "_m_undo.h"
  17. class CRchTxtPtr;
  18. class CTxtEdit;
  19. class CTxtIStream;
  20. /*
  21. * CTxtPtr
  22. *
  23. * @class
  24. * provides access to the array of characters in the backing store
  25. * (i.e. <c CTxtArray>)
  26. *
  27. * @base public | CRunPtr<lt>CTxtArray<gt>
  28. *
  29. * @devnote
  30. * The state transitions for this object are the same as those for
  31. * <c CRunPtrBase>. <md CTxtPtr::_cp> simply caches the current
  32. * cp (even though it can be derived from _iRun and _ich). _cp is
  33. * used frequently enough (and computing may be expensive) that
  34. * caching the value is worthwhile.
  35. *
  36. * CTxtPtr's *may* be put on the stack, but do so with extreme
  37. * caution. These objects do *not* float; if a change is made to
  38. * the backing store while a CTxtPtr is active, it will be out
  39. * of sync and may lead to a crash. If such a situation may
  40. * exist, use a <c CTxtRange> instead (as these float and keep
  41. * their internal text && format run pointers up-to-date).
  42. *
  43. * Otherwise, a CTxtPtr is a useful, very lightweight plain
  44. * text scanner.
  45. */
  46. // FindEOP() result flags. Low byte used for cchEOP
  47. #define FEOP_CELL 256
  48. #define FEOP_EOP 512
  49. // FindWhiteSpace input flags
  50. #define FWS_SKIP 1
  51. #define FWS_BOUNDTOPARA 2
  52. #define FWS_MOVE 256
  53. class CTxtPtr : public CRunPtr<CTxtBlk>
  54. {
  55. // Only CRchTxtPtr is allowed to call private methods like replace range.
  56. friend class CRchTxtPtr;
  57. //@access Public Methods
  58. public:
  59. #ifdef DEBUG
  60. BOOL Invariant( void ) const; //@cmember Invariant checking
  61. void Update_pchCp() const;
  62. void MoveGapToEndOfBlock () const;
  63. #endif // DEBUG
  64. CTxtPtr(CTxtEdit *ped, LONG cp); //@cmember Constructor
  65. CTxtPtr(const CTxtPtr &tp); //@cmember Copy Constructor
  66. LONG GetText(LONG cch, TCHAR *pch); //@cmember Fetch <p cch> chars
  67. #ifndef NOCOMPLEXSCRIPTS
  68. //@cmember Fetch <p cch> chars with usp xlat
  69. LONG GetTextForUsp(LONG cch, TCHAR *pch, BOOL fNeutralOverride);
  70. #endif
  71. LONG GetPlainText(LONG cch, WCHAR *pchBuff,
  72. LONG cpMost, BOOL fTextize, BOOL fUseCRLF = TRUE);
  73. WCHAR NextCharCount(LONG& cch); //@cmember Move, GetChar, decrement
  74. WCHAR NextChar(); //@cmember Advance to & return next char
  75. WCHAR PrevChar(); //@cmember Backup to & return previous char
  76. WCHAR GetChar(); //@cmember Fetch char at current cp
  77. WCHAR GetPrevChar(); //@cmember Fetch char at previous cp
  78. LONG GetTextLength() const; //@cmember Get total cch for this document
  79. const WCHAR* GetPch(LONG& cchValid) const;//@cmember Get ptr to block of chars
  80. //@cmember Get ptr to a reverse block of chars
  81. const WCHAR* GetPchReverse(LONG& cchValidReverse, LONG* pcchValid = NULL) const;
  82. QWORD GetCharFlagsInRange(LONG cch, BYTE bCharSetDefault);
  83. // The text array has its own versions of these methods (overuling
  84. // those in runptr base so that <md CTxtPtr::_cp> can be correctly
  85. // maintained.
  86. LONG BindToCp(LONG cp); //@cmember Rebinds text pointer to cp
  87. LONG SetCp(LONG cp); //@cmember Sets the cp for the run ptr
  88. LONG GetCp() const //@cmember Gets the current cp
  89. {
  90. // NB! Don't do invariant checking here so floating
  91. // range mechanism can work OK
  92. return _cp;
  93. };
  94. void Zombie(); //@cmember Turn this tp into a zombie
  95. LONG Move(LONG cch); //@cmember Move cp by cch chars
  96. // Advance/backup/adjust safe over CRLF and UTF-16 word pairs
  97. LONG AdjustCRLF(LONG iDir = -1);//@cmember Backup to start of multichar
  98. LONG AdvanceCRLF(BOOL fMulticharAdvance = TRUE); //@cmember Advance over multichar
  99. //@cmember Backup over multichar
  100. LONG BackupCRLF(BOOL fMulticharBackup = TRUE);
  101. BOOL IsAtStartOfCell(); //@cmember Does GetCp() follow a CELL or SOTR?
  102. BOOL IsAfterEOP(); //@cmember Does GetCp() follow an EOP?
  103. BOOL IsAfterTRD(WCHAR ch);//@cmember Does _cp follow table-row delimiter?
  104. BOOL IsAtBOSentence(); //@cmember At beginning of a sentence?
  105. BOOL IsAtBOWord(); //@cmember At beginning of word?
  106. BOOL IsAtEOP(); //@cmember Is _cp at an EOP marker?
  107. BOOL IsAtTRD(WCHAR ch); //@cmember Is _cp at table-row delimiter?
  108. LONG MoveWhile(LONG cchRun, WCHAR chFirst, WCHAR chLast, BOOL fInRange);
  109. // Search
  110. //@cmember Find indicated text
  111. LONG FindText(LONG cpMost, DWORD dwFlags, WCHAR const *pch, LONG cch);
  112. //@cmember Find next EOP
  113. LONG FindEOP(LONG cchMax, LONG *pResults = NULL);
  114. //@cmember Find next exact match to <p pch>
  115. LONG FindExact(LONG cchMax, WCHAR *pch);
  116. LONG FindBOSentence(LONG cch); //@cmember Find beginning of sentence
  117. LONG FindOrSkipWhiteSpaces(LONG cchMax, DWORD dwFlags = 0, DWORD* pdwResult = NULL);
  118. LONG FindWhiteSpaceBound(LONG cchMin, LONG& cpStart, LONG& cpEnd, DWORD dwFlags = 0);
  119. // Word break support
  120. LONG FindWordBreak(INT action, LONG cpMost = -1);//@cmember Find next word break
  121. LONG TranslateRange(LONG cch, UINT CodePage,
  122. BOOL fSymbolCharSet, IUndoBuilder *publdr);
  123. //@access Private methods and data
  124. private:
  125. //@cmember Replace <p cchOld> characters with
  126. // <p cchNew> characters from <p pch>
  127. LONG ReplaceRange(LONG cchOld, LONG cchNew, WCHAR const *pch,
  128. IUndoBuilder *publdr, IAntiEvent *paeCF,
  129. IAntiEvent *paePF);
  130. //@cmember undo helper
  131. void HandleReplaceRangeUndo(LONG cchOld, LONG cchNew,
  132. IUndoBuilder *publdr, IAntiEvent *paeCF,
  133. IAntiEvent *paePF);
  134. //@cmember Insert a range of text helper
  135. // for ReplaceRange
  136. LONG InsertRange(LONG cch, WCHAR const *pch);
  137. void DeleteRange(LONG cch); //@cmember Delete range of text helper
  138. // for ReplaceRange
  139. // support class for FindText
  140. class CTxtFinder
  141. {
  142. public:
  143. BOOL FindText(const CTxtPtr &tp, LONG cpMost, DWORD dwFlags,
  144. const WCHAR *pchToFind, LONG cchToFind,
  145. LONG &cpFirst, LONG &cpLast);
  146. //@cmember Same functionality as CTxtPtr::FindText wrapper
  147. private:
  148. inline BOOL CharComp(WCHAR ch1, WCHAR ch2) const;
  149. inline BOOL CharCompIgnoreCase(WCHAR ch1, WCHAR ch2) const;
  150. LONG FindChar(WCHAR ch, CTxtIStream &tistr);
  151. //@cmember Advances cp to char matching ch from CTxtIStream
  152. LONG MatchString(const WCHAR *pchToFind, LONG cchToFind, CTxtIStream &tistr);
  153. //@cmember Advances cp if chars in pchToFind match next chars from CTxtIStream
  154. LONG MatchStringBiDi(const WCHAR *pchToFind, LONG cchToFind, CTxtIStream &tistr);
  155. //@cmember Like MatchString, but with checks for special Arabic/Hebrew chars
  156. LONG _cchToSearch; //@cmember # of chars to search for current FindText call
  157. BOOL _fSearchForward;
  158. BOOL _fIgnoreCase;
  159. BOOL _fMatchAlefhamza; //@cmember Flags derived from dwFlags from FindText for
  160. BOOL _fMatchKashida; // Arabic/Hebrew searches
  161. BOOL _fMatchDiac;
  162. int _iDirection; //@cmember +/-1 to step through pchToFind
  163. };
  164. LONG _cp; //@cmember Character position in text stream
  165. #ifdef DEBUG
  166. const WCHAR *_pchCp; // Points to string at cp for ease in debugging
  167. #endif
  168. public:
  169. CTxtEdit * _ped; //@cmember Ptr to text edit class needed for
  170. // things like word break proc and used a lot
  171. // by derived classes
  172. };
  173. /*
  174. * CTxtIStream
  175. *
  176. * @class
  177. * Refinement of the CTxtPtr class which implements an istream-like interface.
  178. * Given a CTxtPtr and a direction, a CTxtFinder object returns a char
  179. * for every call to GetChar. No putzing around with the buffer gap is
  180. * necessary, and expensive calls to Move and GetPch are kept to an
  181. * absolute minimum.
  182. *
  183. * @base private | CTxtPtr
  184. *
  185. * @devnote
  186. * At present, this class is used in the implementation of the CTxtFinder
  187. * class. Finds require fast scanning of the sequence of characters leading
  188. * in either direction from the cp. Calls to Move and GetPch slow down
  189. * such scanning significantly, so this class implements a unidirectional
  190. * istream-like scanner which avoids unnecessary calls to these expensive
  191. * CTxtPtr methods.
  192. */
  193. class CTxtIStream : private CTxtPtr
  194. {
  195. public:
  196. enum { DIR_FWD, DIR_REV };
  197. typedef WCHAR (CTxtIStream::*PFNGEWCHAR)();
  198. //@cmember Creates istr to read in iDir
  199. CTxtIStream(const CTxtPtr &tp, int iDir);
  200. inline WCHAR GetChar() //@cmember Returns next char in stream dir
  201. { return (this->*_pfnGetChar)(); }
  202. private:
  203. WCHAR GetNextChar(); //@cmember Returns next char in fwd dir
  204. WCHAR GetPrevChar(); //@cmember Returns next char in rev dir
  205. void FillPchFwd(); //@cmember Refreshes _pch and _cch with chars in fwd dir
  206. void FillPchRev(); //@cmember Refreshes _pch and _cch with chars in rev dir
  207. PFNGEWCHAR _pfnGetChar; //@cmember Func ptr to routine which get next char in iDir
  208. LONG _cch; //@cmember Count of valid chars in _pch in iDir
  209. const WCHAR *_pch; //@cmember Next _cch chars in iDir
  210. };
  211. // ======================= Misc. routines ====================================================
  212. void TxCopyText(WCHAR const *pchSrc, WCHAR *pchDst, LONG cch);
  213. //LONG TxFindEOP(const WCHAR *pchBuff, LONG cch);
  214. INT CALLBACK TxWordBreakProc(WCHAR const *pch, INT ich, INT cb, INT action);
  215. #endif