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.

302 lines
10 KiB

  1. /*
  2. * _SELECT.H
  3. *
  4. * Purpose:
  5. * CTxtSelection class
  6. *
  7. * Owner:
  8. * David R. Fulmer (original code)
  9. * Christian Fortini
  10. *
  11. * Copyright (c) 1995-2000, Microsoft Corporation. All rights reserved.
  12. */
  13. #ifndef _SELECT_H
  14. #define _SELECT_H
  15. #include "_range.h"
  16. #include "_m_undo.h"
  17. // amount of time, in milisecs, before pending characters force a display update
  18. #define ticksPendingUpdate 100 // 100 mili secs ~ display at least 10 characters per second.
  19. class CDisplay;
  20. class CLinePtr;
  21. typedef enum
  22. {
  23. smNone,
  24. smWord,
  25. smLine,
  26. smPara
  27. } SELMODE;
  28. enum
  29. {
  30. CARET_NONE = 0,
  31. CARET_CUSTOM = 1,
  32. CARET_BIDI = 2,
  33. CARET_THAI = 4,
  34. CARET_INDIC = 8
  35. };
  36. class CTxtSelection : public CTxtRange
  37. {
  38. #ifdef DEBUG
  39. public:
  40. BOOL Invariant( void ) const; // Invariant checking.
  41. #endif // DEBUG
  42. //@access Protected Data
  43. protected:
  44. CDisplay *_pdp; // display this selection belong to
  45. LONG _cpSel; // active end of displayed selection
  46. LONG _cchSel; // length of displayed selection
  47. LONG _upCaret; // caret x on screen
  48. LONG _vpCaret; // caret y on screen
  49. LONG _upCaretReally; // real caret x (/r start of line) for vertical moves
  50. INT _dvpCaret; // caret height
  51. union
  52. {
  53. DWORD _dwFlags; // All together now
  54. struct
  55. {
  56. DWORD _fCaretNotAtBOL:1; // If at BOL, show caret at prev EOL
  57. DWORD _fDeferUpdate :1; // Defer updating selection/caret on screen
  58. DWORD _fInAutoWordSel:1; // Current selection used auto word sel
  59. DWORD _fShowCaret :1; // Show caret on screen
  60. DWORD _fShowSelection:1; // Show selection on screen
  61. DWORD _fIsChar :1; // Currently adding a single char
  62. DWORD _fObSelected :1; // An embedded object is selected
  63. DWORD _fAutoSelectAborted : 1; // Whether auto word selection is aborted
  64. DWORD _fCaretCreated :1; // Caret has been created
  65. DWORD _fNoKeyboardUpdate :1; // Keyboard is not updated while in UpdateCaret()
  66. DWORD _fEOP :1; // InsertEOP() has been called
  67. DWORD _fHomeOrEnd :1; // Home or End key is being processed
  68. DWORD _fAutoVScroll :1; // 1.0 specific: flag indicating autoscrolling should be applied
  69. DWORD _fForceScrollCaret:1; // 1.0 specific: force caret to scroll
  70. DWORD _fShowCellLine :1; // Show line for CELL following TRED
  71. DWORD _fUpdatedFromCp0:1;// Updated selection from cp = 0
  72. };
  73. };
  74. SELMODE _SelMode; // 0 none, 1 Word, 2 Line, 3 Paragraph
  75. DWORD _ticksPending; // Count of chars inserted without UpdateWindow
  76. LONG _cpAnchor; // Initial anchor for auto word select
  77. LONG _cpAnchorMin; // Initial selection cpMin/cpMost for select
  78. LONG _cpAnchorMost; // modes
  79. LONG _cpWordMin; // Start of anchor word in word select mode
  80. LONG _cpWordMost; // End of anchor word in word select mode
  81. LONG _cpWordPrev; // Previous anchor word end
  82. HBITMAP _hbmpCaret; // Used for funky carets, like BiDi/ital carets
  83. DWORD _dwCaretInfo; // Current caret info used to avoid new create
  84. //@access Public Methods
  85. public:
  86. CTxtSelection(CDisplay * const pdp);
  87. ~CTxtSelection();
  88. CRchTxtPtr& operator =(const CRchTxtPtr& rtp);
  89. CTxtRange& operator =(const CTxtRange &rg);
  90. // Set the display
  91. void SetDisplay(CDisplay *pdp) { _pdp = pdp; }
  92. // Information for Selection Change notification
  93. void SetSelectionInfo(SELCHANGE *pselchg);
  94. // Replacement
  95. LONG DeleteWithTRDCheck(IUndoBuilder *publdr, SELRR selaemode,
  96. LONG *pcchMove, DWORD dwflags);
  97. LONG ReplaceRange(LONG cchNew, WCHAR const *pch,
  98. IUndoBuilder *publdr, SELRR fCreateAE, LONG* pcchMove = NULL,
  99. DWORD dwFlags = 0);
  100. // Info for recalc line / UpdateView
  101. void ClearCchPending() {_ticksPending = 0;}
  102. LONG GetScrSelMin() const {return min(_cpSel, _cpSel - _cchSel);}
  103. LONG GetScrSelMost() const {return max(_cpSel, _cpSel - _cchSel);}
  104. BOOL PuttingChar() const {return _fIsChar;}
  105. // General updating
  106. virtual BOOL Update(BOOL fScrollIntoView);
  107. BOOL DeferUpdate()
  108. {const BOOL fRet = _fDeferUpdate; _fDeferUpdate = TRUE; return fRet;}
  109. BOOL DoDeferedUpdate(BOOL fScrollIntoView)
  110. {_fDeferUpdate = FALSE; return Update(fScrollIntoView);}
  111. void SetAutoVScroll(BOOL bAuto) {_fAutoVScroll = bAuto;}
  112. BOOL GetAutoVScroll() {return _fAutoVScroll;}
  113. BOOL GetShowCellLine() {return _fShowCellLine;}
  114. void SetForceScrollCaret(BOOL bAuto) {_fForceScrollCaret = bAuto;}
  115. BOOL GetForceScrollCaret() {return _fForceScrollCaret;}
  116. // method used by selection anti-event for out-of-phase updates
  117. void SetDelayedSelectionRange(LONG cp, LONG cch);
  118. void StopGroupTyping();
  119. // Caret management
  120. BOOL CaretNotAtBOL() const;
  121. void CheckTableIP(BOOL fOpenLine);
  122. void CreateCaret();
  123. void DeleteCaretBitmap(BOOL fReset);
  124. BOOL IsCaretHorizontal() const;
  125. INT GetCaretHt() {return _dvpCaret;}
  126. LONG GetUpCaretReally();
  127. LONG GetUpCaret() const {return _upCaret;}
  128. LONG GetVpCaret() const {return _vpCaret;}
  129. BOOL IsCaretNotAtBOL() const {return _fCaretNotAtBOL;}
  130. BOOL IsCaretInView() const;
  131. BOOL IsCaretShown() const {return _fShowCaret && !_cch;}
  132. BOOL IsUpdatedFromCp0() const {return _fUpdatedFromCp0;}
  133. LONG LineLength(LONG *pcp) const;
  134. BOOL SetUpPosition(LONG upCaret, CLinePtr& rp, BOOL fBottomLine, BOOL fExtend);
  135. BOOL ShowCaret(BOOL fShow);
  136. BOOL UpdateCaret(BOOL fScrollIntoView, BOOL fForceCaret = FALSE);
  137. BOOL GetCaretPoint(RECTUV &rcClient, POINTUV &pt, CLinePtr *prp, BOOL fBeforeCp);
  138. BOOL MatchKeyboardToPara();
  139. // Selection management
  140. void ClearPrevSel() { _cpSel = 0; _cchSel = 0; }
  141. BOOL GetShowSelection() {return _fShowSelection;}
  142. BOOL ScrollWindowful(WPARAM wparam, BOOL fExtend);
  143. void SetSelection(LONG cpFirst, LONG cpMost);
  144. BOOL ShowSelection(BOOL fShow);
  145. void Beep() {GetPed()->Beep();}
  146. // Selection with the mouse
  147. void CancelModes (BOOL fAutoWordSel = FALSE);
  148. void ExtendSelection(const POINTUV pt);
  149. BOOL PointInSel (const POINTUV pt, RECTUV *prcClient = NULL, HITTEST Hit = HT_Undefined) const;
  150. void SelectAll ();
  151. void SelectUnit (const POINTUV pt, LONG Unit);
  152. void SelectWord (const POINTUV pt);
  153. void SetCaret (const POINTUV pt, BOOL fUpdate = TRUE);
  154. // Keyboard movements
  155. BOOL Left (BOOL fCtrl, BOOL fExtend);
  156. BOOL Right (BOOL fCtrl, BOOL fExtend);
  157. BOOL Up (BOOL fCtrl, BOOL fExtend);
  158. BOOL Down (BOOL fCtrl, BOOL fExtend);
  159. BOOL Home (BOOL fCtrl, BOOL fExtend);
  160. BOOL End (BOOL fCtrl, BOOL fExtend);
  161. BOOL PageUp (BOOL fCtrl, BOOL fExtend);
  162. BOOL PageDown(BOOL fCtrl, BOOL fExtend);
  163. // Editing
  164. BOOL PutChar (DWORD ch, DWORD dwFlags, IUndoBuilder *publdr, LCID lcid = 0);
  165. void SetIsChar(BOOL);
  166. void CheckUpdateWindow();
  167. BOOL InsertEOP(IUndoBuilder *publdr, WCHAR ch = 0);
  168. LONG InsertTableRow (const CParaFormat *pPF, IUndoBuilder *publdr,
  169. BOOL fFixCellBorders = FALSE);
  170. // Keyboard switching support.
  171. void CheckChangeKeyboardLayout();
  172. bool CheckChangeFont (const HKL hkl, UINT iCharRep, LONG iSelFormat = 0, QWORD qwCharFlags = 0);
  173. UINT CheckSynchCharSet(QWORD dwCharFlags = 0);
  174. // from CTxtRange
  175. BOOL Delete (DWORD flags, IUndoBuilder *publdr);
  176. BOOL Backspace(BOOL fCtrl, IUndoBuilder *publdr);
  177. const CParaFormat* GetPF();
  178. // note that the parameters are different than CTxtRange::SetCharFormat
  179. // intentionally; the selection has extra options available to it.
  180. HRESULT SetCharFormat(const CCharFormat *pCF, DWORD flags,
  181. IUndoBuilder *publdr, DWORD dwMask, DWORD dwMask2);
  182. HRESULT SetParaFormat(const CParaFormat *pPF,
  183. IUndoBuilder *publdr, DWORD dwMask, DWORD dwMask2);
  184. // Auto word selection helper
  185. void InitClickForAutWordSel(const POINTUV pt);
  186. // dual font helper for CTxtSelection::PutChar
  187. void SetupDualFont();
  188. // IUnknown and IDispatch methods handled by CTxtRange methods
  189. // ITextRange methods can use ITextRange methods directly, since
  190. // they either don't modify the display of the selection (get methods), or
  191. // they have appropriate virtual character to call on selection functions.
  192. // ITextSelection methods
  193. STDMETHODIMP GetFlags (long *pFlags) ;
  194. STDMETHODIMP SetFlags (long Flags) ;
  195. STDMETHODIMP GetType (long *pType) ;
  196. STDMETHODIMP MoveLeft (long pUnit, long Count, long Extend,
  197. long *pDelta) ;
  198. STDMETHODIMP MoveRight(long pUnit, long Count, long Extend,
  199. long *pDelta) ;
  200. STDMETHODIMP MoveUp (long pUnit, long Count, long Extend,
  201. long *pDelta) ;
  202. STDMETHODIMP MoveDown (long pUnit, long Count, long Extend,
  203. long *pDelta) ;
  204. STDMETHODIMP HomeKey (long pUnit, long Extend, long *pDelta) ;
  205. STDMETHODIMP EndKey (long pUnit, long Extend, long *pDelta) ;
  206. STDMETHODIMP TypeText (BSTR bstr) ;
  207. STDMETHODIMP SetPoint (long x, long y, long Extend) ;
  208. //@access Protected Methods
  209. protected:
  210. // Protected update method
  211. void UpdateSelection();
  212. // Protected caret management method
  213. INT GetCaretHeight(INT *pyDescent) const;
  214. HRESULT GeoMover (long Unit, long Count, long Extend,
  215. long *pDelta, LONG iDir);
  216. HRESULT Homer (long Unit, long Extend, long *pDelta,
  217. BOOL (CTxtSelection::*pfn)(BOOL, BOOL));
  218. // Auto Select Word Helpers
  219. void UpdateForAutoWord();
  220. void AutoSelGoBackWord(
  221. LONG *pcpToUpdate,
  222. int iDirToPrevWord,
  223. int iDirToNextWord);
  224. void ExtendToWordBreak(BOOL fAfterEOP, INT iDir);
  225. BOOL CheckPlainTextFinalEOP();
  226. };
  227. /*
  228. * CSelPhaseAdjuster
  229. *
  230. * @class This class is put on the stack and used to temporarily hold
  231. * selection cp values until the control is "stable" (and thus,
  232. * we can safely set the selection
  233. */
  234. class CSelPhaseAdjuster : public IReEntrantComponent
  235. {
  236. //@access Public methods
  237. public:
  238. // IReEntrantComponent methods
  239. virtual void OnEnterContext() {;} //@cmember re-entered notify
  240. CSelPhaseAdjuster(CTxtEdit *ped); //@cmember constructor
  241. ~CSelPhaseAdjuster(); //@cmember destructor
  242. void CacheRange(LONG cp, LONG cch); //@cmember stores the sel range
  243. //@access Private data
  244. private:
  245. CTxtEdit * _ped; //@cmember edit context
  246. LONG _cp; //@cmember sel active end to set
  247. LONG _cch; //@cmember sel extension
  248. };
  249. #endif