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.

244 lines
9.0 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-1998, 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_ADVANCECP 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 MoveGapToEndOfBlock () const;
  62. #endif // DEBUG
  63. CTxtPtr(CTxtEdit *ped, LONG cp); //@cmember Constructor
  64. CTxtPtr(const CTxtPtr &tp); //@cmember Copy Constructor
  65. LONG GetText(LONG cch, TCHAR *pch); //@cmember Fetch <p cch> chars
  66. //@cmember Fetch <p cch> chars with usp xlat
  67. LONG GetTextForUsp(LONG cch, TCHAR *pch, BOOL fNeutralOverride);
  68. //@cmember Fetch <p cch> chars with xlat
  69. LONG GetPlainText(LONG cch, TCHAR *pchBuff,
  70. LONG cpMost, BOOL fTextize, BOOL fAdjustCRLF = TRUE);
  71. TCHAR NextCharCount(LONG& cch); //@cmember Advance, GetChar, decrement
  72. TCHAR NextChar(); //@cmember Advance to & return next char
  73. TCHAR PrevChar(); //@cmember Backup to & return previous char
  74. TCHAR GetChar(); //@cmember Fetch char at current cp
  75. TCHAR GetPrevChar(); //@cmember Fetch char at previous cp
  76. LONG GetTextLength() const; //@cmember Get total cch for this document
  77. const TCHAR* GetPch(LONG& cchValid) const;//@cmember Get ptr to block of chars
  78. //@cmember Get ptr to a reverse block of chars
  79. const TCHAR* GetPchReverse(LONG& cchValidReverse, LONG* pcchValid = NULL);
  80. // The text array has its own versions of these methods (overuling
  81. // those in runptr base so that <md CTxtPtr::_cp> can be correctly
  82. // maintained.
  83. LONG BindToCp(LONG cp); //@cmember Rebinds text pointer to cp
  84. LONG SetCp(LONG cp); //@cmember Sets the cp for the run ptr
  85. LONG GetCp() const //@cmember Gets the current cp
  86. {
  87. // NB! Don't do invariant checking here so floating
  88. // range mechanism can work OK
  89. return _cp;
  90. };
  91. void Zombie(); //@cmember Turn this tp into a zombie
  92. LONG AdvanceCp(LONG cch);//@cmember Advance cp by cch chars
  93. // Advance/backup/adjust safe over CRLF and UTF-16 word pairs
  94. LONG AdjustCpCRLF(); //@cmember Backup to start of multichar
  95. LONG AdvanceCpCRLF(BOOL fMulticharAdvance = TRUE); //@cmember Advance over multichar
  96. //@cmember Backup over multichar
  97. LONG BackupCpCRLF(BOOL fMulticharBackup = TRUE);
  98. BOOL IsAfterEOP(); //@cmember Does current cp follow an EOP?
  99. BOOL IsAtEOP(); //@cmember Is current cp at an EOP marker?
  100. BOOL IsAtBOSentence(); //@cmember At beginning of a sentence?
  101. BOOL IsAtBOWord(); //@cmember At beginning of word?
  102. LONG MoveWhile(LONG cchRun, WCHAR chFirst, WCHAR chLast, BOOL fInRange);
  103. // Search
  104. //@cmember Find indicated text
  105. LONG FindText(LONG cpMost, DWORD dwFlags, TCHAR const *pch, LONG cch);
  106. //@cmember Find next EOP
  107. LONG FindEOP(LONG cchMax, LONG *pResults = NULL);
  108. //@cmember Find next exact match to <p pch>
  109. LONG FindExact(LONG cchMax, TCHAR *pch);
  110. LONG FindBOSentence(LONG cch); //@cmember Find beginning of sentence
  111. LONG FindOrSkipWhiteSpaces(LONG cchMax, DWORD dwFlags = 0, DWORD* pdwResult = NULL);
  112. LONG FindWhiteSpaceBound(LONG cchMin, LONG& cpStart, LONG& cpEnd, DWORD dwFlags = 0);
  113. // Word break support
  114. LONG FindWordBreak(INT action, LONG cpMost = -1);//@cmember Find next word break
  115. LONG TranslateRange(LONG cch, UINT CodePage,
  116. BOOL fSymbolCharSet, IUndoBuilder *publdr);
  117. //@access Private methods and data
  118. private:
  119. //@cmember Replace <p cchOld> characters with
  120. // <p cchNew> characters from <p pch>
  121. LONG ReplaceRange(LONG cchOld, LONG cchNew, TCHAR const *pch,
  122. IUndoBuilder *publdr, IAntiEvent *paeCF,
  123. IAntiEvent *paePF);
  124. //@cmember undo helper
  125. void HandleReplaceRangeUndo(LONG cchOld, LONG cchNew,
  126. IUndoBuilder *publdr, IAntiEvent *paeCF,
  127. IAntiEvent *paePF);
  128. //@cmember Insert a range of text helper
  129. // for ReplaceRange
  130. LONG InsertRange(LONG cch, TCHAR const *pch);
  131. void DeleteRange(LONG cch); //@cmember Delete range of text helper
  132. // for ReplaceRange
  133. // support class for FindText
  134. class CTxtFinder
  135. {
  136. public:
  137. BOOL FindText(const CTxtPtr &tp, LONG cpMost, DWORD dwFlags,
  138. const TCHAR *pchToFind, LONG cchToFind,
  139. LONG &cpFirst, LONG &cpLast);
  140. //@cmember Same functionality as CTxtPtr::FindText wrapper
  141. private:
  142. inline BOOL CharComp(TCHAR ch1, TCHAR ch2) const;
  143. inline BOOL CharCompIgnoreCase(TCHAR ch1, TCHAR ch2) const;
  144. LONG FindChar(TCHAR ch, CTxtIStream &tistr);
  145. //@cmember Advances cp to char matching ch from CTxtIStream
  146. LONG MatchString(const TCHAR *pchToFind, LONG cchToFind, CTxtIStream &tistr);
  147. //@cmember Advances cp if chars in pchToFind match next chars from CTxtIStream
  148. LONG MatchStringBiDi(const TCHAR *pchToFind, LONG cchToFind, CTxtIStream &tistr);
  149. //@cmember Like MatchString, but with checks for special Arabic/Hebrew chars
  150. LONG _cchToSearch; //@cmember # of chars to search for current FindText call
  151. BOOL _fSearchForward;
  152. BOOL _fIgnoreCase;
  153. BOOL _fMatchAlefhamza; //@cmember Flags derived from dwFlags from FindText for
  154. BOOL _fMatchKashida; // Arabic/Hebrew searches
  155. BOOL _fMatchDiac;
  156. int _iDirection; //@cmember +/-1 to step through pchToFind
  157. };
  158. LONG _cp; //@cmember Character position in text stream
  159. #ifdef DEBUG
  160. const WCHAR *_pchCp; // Points to string at cp for ease in debugging
  161. #endif
  162. public:
  163. CTxtEdit * _ped; //@cmember Ptr to text edit class needed for
  164. // things like word break proc and used a lot
  165. // by derived classes
  166. };
  167. /*
  168. * CTxtIStream
  169. *
  170. * @class
  171. * Refinement of the CTxtPtr class which implements an istream-like interface.
  172. * Given a CTxtPtr and a direction, a CTxtFinder object returns a char
  173. * for every call to GetChar. No putzing around with the buffer gap is
  174. * necessary, and expensive calls to AdvanceCp and GetPch are kept to an
  175. * absolute minimum.
  176. *
  177. * @base private | CTxtPtr
  178. *
  179. * @devnote
  180. * At present, this class is used in the implementation of the CTxtFinder
  181. * class. Finds require fast scanning of the sequence of characters leading
  182. * in either direction from the cp. Calls to AdvanceCp and GetPch slow down
  183. * such scanning significantly, so this class implements a unidirectional
  184. * istream-like scanner which avoids unnecessary calls to these expensive
  185. * CTxtPtr methods.
  186. */
  187. class CTxtIStream : private CTxtPtr
  188. {
  189. public:
  190. enum { DIR_FWD, DIR_REV };
  191. typedef TCHAR (CTxtIStream::*PFNGETCHAR)();
  192. //@cmember Creates istr to read in iDir
  193. CTxtIStream(const CTxtPtr &tp, int iDir);
  194. inline TCHAR GetChar() //@cmember Returns next char in stream dir
  195. { return (this->*_pfnGetChar)(); }
  196. private:
  197. TCHAR GetNextChar(); //@cmember Returns next char in fwd dir
  198. TCHAR GetPrevChar(); //@cmember Returns next char in rev dir
  199. void FillPchFwd(); //@cmember Refreshes _pch and _cch with chars in fwd dir
  200. void FillPchRev(); //@cmember Refreshes _pch and _cch with chars in rev dir
  201. PFNGETCHAR _pfnGetChar; //@cmember Func ptr to routine which get next char in iDir
  202. LONG _cch; //@cmember Count of valid chars in _pch in iDir
  203. const TCHAR *_pch; //@cmember Next _cch chars in iDir
  204. };
  205. // ======================= Misc. routines ====================================================
  206. void TxCopyText(TCHAR const *pchSrc, TCHAR *pchDst, LONG cch);
  207. //LONG TxFindEOP(const TCHAR *pchBuff, LONG cch);
  208. INT CALLBACK TxWordBreakProc(TCHAR const *pch, INT ich, INT cb, INT action);
  209. #endif