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.

294 lines
9.3 KiB

  1. /*
  2. * SELECT.C
  3. *
  4. * Purpose:
  5. * CTxtSelection class
  6. *
  7. * Owner:
  8. * David R. Fulmer (original code)
  9. * Christian Fortini
  10. *
  11. * Copyright (c) 1995-1997, 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 _xCaret; // caret x on screen
  48. LONG _yCaret; // caret y on screen
  49. LONG _xCaretReally; // real caret x (/r start of line) for vertical moves
  50. INT _yHeightCaret; // 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 craet to scroll
  70. };
  71. };
  72. SELMODE _SelMode; // 0 none, 1 Word, 2 Line, 3 Paragraph
  73. DWORD _ticksPending; // Count of chars inserted without UpdateWindow
  74. LONG _cpAnchor; // Initial anchor for auto word select
  75. LONG _cpAnchorMin; // Initial selection cpMin/cpMost for select
  76. LONG _cpAnchorMost; // modes
  77. LONG _cpWordMin; // Start of anchor word in word select mode
  78. LONG _cpWordMost; // End of anchor word in word select mode
  79. LONG _cpWordPrev; // Previous anchor word end
  80. HBITMAP _hbmpCaret; // Used for funky carets, like BiDi/ital carets
  81. DWORD _dwCaretInfo; // Current caret info used to avoid new create
  82. //@access Public Methods
  83. public:
  84. CTxtSelection(CDisplay * const pdp);
  85. ~CTxtSelection();
  86. CRchTxtPtr& operator =(const CRchTxtPtr& rtp);
  87. CTxtRange& operator =(const CTxtRange &rg);
  88. // Set the display
  89. void SetDisplay(CDisplay *pdp) { _pdp = pdp; }
  90. // Information for Selection Change notification
  91. void SetSelectionInfo(SELCHANGE *pselchg);
  92. // Replacement
  93. LONG ReplaceRange(LONG cchNew, TCHAR const *pch,
  94. IUndoBuilder *publdr, SELRR fCreateAE, LONG* pcchMove = NULL, DWORD dwFlags = 0);
  95. // Info for recalc line / UpdateView
  96. void ClearCchPending() {_ticksPending = 0;}
  97. LONG GetScrSelMin() const {return min(_cpSel, _cpSel - _cchSel);}
  98. LONG GetScrSelMost() const {return max(_cpSel, _cpSel - _cchSel);}
  99. BOOL PuttingChar() const {return _fIsChar;}
  100. // General updating
  101. virtual BOOL Update(BOOL fScrollIntoView);
  102. BOOL DeferUpdate()
  103. {const BOOL fRet = _fDeferUpdate; _fDeferUpdate = TRUE; return fRet;}
  104. BOOL DoDeferedUpdate(BOOL fScrollIntoView)
  105. {_fDeferUpdate = FALSE; return Update(fScrollIntoView);}
  106. void SetAutoVScroll(BOOL bAuto) {_fAutoVScroll = bAuto;}
  107. BOOL GetAutoVScroll() {return _fAutoVScroll;}
  108. void SetForceScrollCaret(BOOL bAuto) {_fForceScrollCaret = bAuto;}
  109. BOOL GetForceScrollCaret() {return _fForceScrollCaret;}
  110. // method used by selection anti-event for out-of-phase updates
  111. void SetDelayedSelectionRange(LONG cp, LONG cch);
  112. void StopGroupTyping();
  113. // Caret management
  114. BOOL CaretNotAtBOL() const;
  115. void CreateCaret();
  116. void DeleteCaretBitmap(BOOL fReset);
  117. INT GetCaretHt() {return _yHeightCaret;}
  118. LONG GetXCaretReally();
  119. LONG GetXCaret() const {return _xCaret;}
  120. LONG GetYCaret() const {return _yCaret;}
  121. BOOL IsCaretInView() const;
  122. BOOL IsCaretShown() const {return _fShowCaret && !_cch;}
  123. LONG LineLength(LONG *pcp) const;
  124. BOOL SetXPosition(LONG xCaret, CLinePtr& rp);
  125. BOOL ShowCaret(BOOL fShow);
  126. BOOL UpdateCaret(BOOL fScrollIntoView, BOOL fForceCaret = FALSE);
  127. BOOL GetCaretPoint(RECT &rcClient, POINT &pt, CLinePtr *prp, BOOL fBeforeCp);
  128. BOOL MatchKeyboardToPara();
  129. // Selection management
  130. void ClearPrevSel() { _cpSel = 0; _cchSel = 0; }
  131. BOOL GetShowSelection() {return _fShowSelection;}
  132. BOOL ScrollWindowful(WPARAM wparam);
  133. void SetSelection(LONG cpFirst, LONG cpMost);
  134. BOOL ShowSelection(BOOL fShow);
  135. void Beep() {GetPed()->Beep();}
  136. // Selection with the mouse
  137. void CancelModes (BOOL fAutoWordSel = FALSE);
  138. void ExtendSelection(const POINT pt);
  139. BOOL PointInSel (const POINT pt, const RECT *prcClient,
  140. HITTEST Hit = HT_Undefined) const;
  141. void SelectAll ();
  142. void SelectUnit (const POINT pt, LONG Unit);
  143. void SelectWord (const POINT pt);
  144. void SetCaret (const POINT pt, BOOL fUpdate = TRUE);
  145. // Keyboard movements
  146. BOOL Left (BOOL fCtrl);
  147. BOOL Right (BOOL fCtrl);
  148. BOOL Up (BOOL fCtrl);
  149. BOOL Down (BOOL fCtrl);
  150. BOOL Home (BOOL fCtrl);
  151. BOOL End (BOOL fCtrl);
  152. BOOL PageUp (BOOL fCtrl);
  153. BOOL PageDown(BOOL fCtrl);
  154. // Editing
  155. BOOL BypassHiddenText(LONG iDir);
  156. BOOL PutChar (TCHAR ch, DWORD dwFlags, IUndoBuilder *publdr);
  157. void SetIsChar(BOOL);
  158. void CheckUpdateWindow();
  159. void CheckTableSelection();
  160. BOOL InsertEOP(IUndoBuilder *publdr, WCHAR ch = 0);
  161. // Keyboard switching support.
  162. void CheckChangeKeyboardLayout();
  163. bool CheckChangeFont (const HKL hkl, UINT cp, LONG iSelFormat = 0, DWORD dwCharFlag = 0);
  164. UINT CheckSynchCharSet(DWORD dwCharFlag = 0);
  165. // from CTxtRange
  166. BOOL Delete (DWORD flags, IUndoBuilder *publdr);
  167. BOOL Backspace(BOOL fCtrl, IUndoBuilder *publdr);
  168. const CParaFormat* GetPF();
  169. // note that the parameters are different than CTxtRange::SetCharFormat
  170. // intentionally; the selection has extra options available to it.
  171. HRESULT SetCharFormat(const CCharFormat *pCF, DWORD flags,
  172. IUndoBuilder *publdr, DWORD dwMask, DWORD dwMask2);
  173. HRESULT SetParaFormat(const CParaFormat *pPF,
  174. IUndoBuilder *publdr, DWORD dwMask);
  175. // Auto word selection helper
  176. void InitClickForAutWordSel(const POINT pt);
  177. // dual font helper for CTxtSelection::PutChar
  178. void SetupDualFont();
  179. // IUnknown and IDispatch methods handled by CTxtRange methods
  180. // ITextRange methods can use ITextRange methods directly, since
  181. // they either don't modify the display of the selection (get methods), or
  182. // they have appropriate virtual character to call on selection functions.
  183. // ITextSelection methods
  184. STDMETHODIMP GetFlags (long *pFlags) ;
  185. STDMETHODIMP SetFlags (long Flags) ;
  186. STDMETHODIMP GetType (long *pType) ;
  187. STDMETHODIMP MoveLeft (long pUnit, long Count, long Extend,
  188. long *pDelta) ;
  189. STDMETHODIMP MoveRight(long pUnit, long Count, long Extend,
  190. long *pDelta) ;
  191. STDMETHODIMP MoveUp (long pUnit, long Count, long Extend,
  192. long *pDelta) ;
  193. STDMETHODIMP MoveDown (long pUnit, long Count, long Extend,
  194. long *pDelta) ;
  195. STDMETHODIMP HomeKey (long pUnit, long Extend, long *pDelta) ;
  196. STDMETHODIMP EndKey (long pUnit, long Extend, long *pDelta) ;
  197. STDMETHODIMP TypeText (BSTR bstr) ;
  198. STDMETHODIMP SetPoint (long x, long y, long Extend) ;
  199. //@access Protected Methods
  200. protected:
  201. // Protected update method
  202. void UpdateSelection();
  203. // Protected caret management method
  204. INT GetCaretHeight(INT *pyDescent) const;
  205. HRESULT GeoMover (long Unit, long Count, long Extend,
  206. long *pDelta, LONG iDir);
  207. HRESULT Homer (long Unit, long Extend, long *pDelta,
  208. BOOL (CTxtSelection::*pfn)(BOOL));
  209. // Auto Select Word Helpers
  210. void UpdateForAutoWord();
  211. void AutoSelGoBackWord(
  212. LONG *pcpToUpdate,
  213. int iDirToPrevWord,
  214. int iDirToNextWord);
  215. void ExtendToWordBreak(BOOL fAfterEOP, INT iDir);
  216. BOOL CheckPlainTextFinalEOP();
  217. };
  218. /*
  219. * CSelPhaseAdjuster
  220. *
  221. * @class This class is put on the stack and used to temporarily hold
  222. * selection cp values until the control is "stable" (and thus,
  223. * we can safely set the selection
  224. */
  225. class CSelPhaseAdjuster : public IReEntrantComponent
  226. {
  227. //@access Public methods
  228. public:
  229. // IReEntrantComponent methods
  230. virtual void OnEnterContext() {;} //@cmember re-entered notify
  231. CSelPhaseAdjuster(CTxtEdit *ped); //@cmember constructor
  232. ~CSelPhaseAdjuster(); //@cmember destructor
  233. void CacheRange(LONG cp, LONG cch); //@cmember stores the sel range
  234. //@access Private data
  235. private:
  236. CTxtEdit * _ped; //@cmember edit context
  237. LONG _cp; //@cmember sel active end to set
  238. LONG _cch; //@cmember sel extension
  239. };
  240. #endif