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.

540 lines
15 KiB

  1. /*
  2. * _DISP.H
  3. *
  4. * Purpose:
  5. * DISP class
  6. *
  7. * Authors:
  8. * Original RichEdit code: David R. Fulmer
  9. * Christian Fortini
  10. * Murray Sargent
  11. *
  12. * Copyright (c) 1995-1998, Microsoft Corporation. All rights reserved.
  13. */
  14. #ifndef _DISP_H
  15. #define _DISP_H
  16. #include "_devdsc.h"
  17. #include "_line.h"
  18. #include "_edit.h"
  19. class CDisplay;
  20. class CLed;
  21. class CLinePtr;
  22. class CTxtStory;
  23. class CTxtEdit;
  24. class CRchTxtPtr;
  25. class CTxtRange;
  26. class CTxtSelection;
  27. #define INVALID_ZOOM_DENOMINATOR 0
  28. // Auto scroll timing
  29. #define cmsecScrollDelay 500
  30. #define cmsecScrollInterval 50
  31. class CDrawInfo;
  32. // ============================ CLed ====================================
  33. // Line Edit Descriptor - describes impact of an edit on line breaks
  34. class CLed
  35. {
  36. public:
  37. LONG _cpFirst; // cp of first affected line
  38. LONG _iliFirst; // index of first affected line
  39. LONG _yFirst; // y offset of first affected line
  40. LONG _cpMatchOld; // pre-edit cp of first matched line
  41. LONG _iliMatchOld; // pre-edit index of first matched line
  42. LONG _yMatchOld; // pre-edit y offset of first matched line
  43. LONG _cpMatchNew; // post-edit cp of first matched line
  44. LONG _iliMatchNew; // post-edit index of first matched line
  45. LONG _yMatchNew; // post-edit y offset of bottom of first matched line
  46. LONG _yMatchNewTop; // post-edit y offset of top of first matched line
  47. public:
  48. CLed();
  49. void SetMax(const CDisplay * const pdp);
  50. };
  51. inline CLed::CLed()
  52. {
  53. #ifdef DEBUG
  54. // We set this invalid so that we can assert on it in debug builds.
  55. _yMatchNewTop = -1;
  56. #endif // DEBUG
  57. }
  58. // An enumeration describing the various display actions we can perform on the selection
  59. enum SELDISPLAYACTION
  60. {
  61. selSetHiLite,
  62. selSetNormal,
  63. selUpdateHiLite,
  64. selUpdateNormal
  65. };
  66. class CDispDim
  67. {
  68. public:
  69. CDispDim(){ZeroMemory(this, sizeof(*this));}
  70. LONG dx;
  71. DWORD lstflow;
  72. };
  73. // Forward declaration to prevent recursion of definitions
  74. class CAccumDisplayChanges;
  75. // ========================== CDisplay ====================================
  76. // Display - keeps track of line breaks for a device.
  77. // All measurements are in pixels on rendering device,
  78. // EXCEPT xWidthMax and yHeightMax, which are in twips.
  79. class CDisplay : public CDevDesc, public ITxNotify
  80. {
  81. friend class CLinePtr;
  82. friend class CLed;
  83. #ifdef DEBUG
  84. public:
  85. BOOL Invariant ( void ) const;
  86. private:
  87. #endif
  88. public:
  89. // Average char width of system font
  90. static INT GetXWidthSys() { return W32->GetXWidthSys(); }
  91. // Height of system font
  92. static INT GetYHeightSys() { return W32->GetYHeightSys(); }
  93. private:
  94. static DWORD _dwTimeScrollNext; // time for next scroll step
  95. static DWORD _dwScrollLast; // last scroll action
  96. CDrawInfo * _pdi; // Draw info parameters
  97. protected:
  98. CAccumDisplayChanges *_padc; // Accumulated display changes if frozen
  99. DWORD _fBgndRecalc :1; // Background recalc is running
  100. DWORD _fDeferUpdateScrollBar:1; // Currently deferring updating scroll bars
  101. DWORD _fHScrollEnabled :1; // Horizontal scrolling enabled
  102. DWORD _fInBkgndRecalc :1; // Avoid reentrant background recalc
  103. DWORD _fLineRecalcErr :1; // Error occured during background recalc
  104. DWORD _fNoUpdateView :1; // Don't update visible view
  105. DWORD _fWordWrap :1; // Word wrap text
  106. DWORD _fNeedRecalc :1; // Recalc line is needed
  107. DWORD _fRecalcDone :1; // Is line recalc done ?
  108. DWORD _fViewChanged :1; // Visible view rect has changed since last Draw
  109. DWORD _fUpdateScrollBarDeferred:1;// scroll bars need to be updated
  110. DWORD _fVScrollEnabled :1; // vertical scrolling enabled
  111. DWORD _fUpdateCaret :1; // Whether Draw needs to update cursor
  112. DWORD _fActive :1; // Whether this display is active
  113. DWORD _fRectInvalid :1; // Entire client rectangle has been
  114. // invalidated. Used only in SL. Put
  115. // here, as usual, to save space
  116. DWORD _fSmoothVScroll :1; // Timer for smooth scrolling installed
  117. DWORD _fFinishSmoothVScroll:1;// TRUE if we're winding down the current smooth scroll
  118. DWORD _fMultiLine :1; // TRUE iff this CDisplay is multiline
  119. SHORT _xWidthView; // View rect width
  120. LONG _yHeightView; // View rect height
  121. LONG _yHeightClient; // Height of client rect unmodified by inset.
  122. LONG _xScroll; // Horizontal scroll position of visible view
  123. LONG _lTempZoomDenominator; // Zoom for GetNaturalSize
  124. LONG _cpFirstVisible; // cp at start of first visible line
  125. // Smooth scroll support.
  126. int _smoothYDelta; // Current # pixels * 1000 to smooth scroll by
  127. int _continuedSmoothYDelta; // At end of 1 smooth scroll cycle, start new with this
  128. int _nextSmoothVScroll; // Fractional amount not yet smooth scrolled
  129. int _totalSmoothVScroll; // Remaining # of device units to smooth scroll
  130. int _continuedSmoothVScroll;// At end of 1 smooth scroll cycle, start new with this
  131. private:
  132. void UpdateViewRectState(const RECT *prcClient);
  133. protected:
  134. LONG GetSelBarInPixels();
  135. friend class CLinePtr;
  136. LONG SetClientHeight(LONG yNewClientHeight);
  137. virtual void InitLinePtr ( CLinePtr & ) = 0;
  138. // Line break recalc.
  139. virtual BOOL RecalcView(BOOL fUpdateScrollBars, RECT* prc = NULL) = 0;
  140. // Rendering
  141. virtual void Render(const RECT &rcView, const RECT &rcRender) = 0;
  142. // Scrollbar
  143. virtual BOOL UpdateScrollBar(INT nBar, BOOL fUpdateRange = FALSE) = 0;
  144. void GetViewDim(LONG& widthView, LONG& heightView);
  145. void SetCpFirstVisible(LONG cp) {_cpFirstVisible = cp;};
  146. LONG ConvertScrollToXPos(LONG xPos);
  147. LONG ConvertXPosToScrollPos(LONG xPos);
  148. virtual LONG GetMaxXScroll() const = 0;
  149. public:
  150. virtual LONG ConvertYPosToScrollPos(LONG yPos);
  151. CDisplay (CTxtEdit* ped);
  152. virtual CDisplay::~CDisplay();
  153. virtual BOOL Init();
  154. void InitFromDisplay(const CDisplay *pdp);
  155. // Device context management
  156. virtual BOOL SetMainTargetDC(HDC hdc, LONG xWidthMax);
  157. virtual BOOL SetTargetDC( HDC hdc, LONG dxpInch = -1, LONG dypInch = -1);
  158. // Getting properties
  159. CTxtEdit* GetPed() const { return _ped;}
  160. CTxtStory* GetStory() const { return _ped->GetTxtStory();}
  161. const CDevDesc* GetDdRender() const { return this;}
  162. virtual const CDevDesc* GetDdTarget() const { return NULL; }
  163. const CDevDesc* GetTargetDev() const;
  164. virtual BOOL IsMain() const = 0;
  165. virtual BOOL IsPrinter() const;
  166. BOOL IsRecalcDone() const { return _fRecalcDone;}
  167. BOOL IsMultiLine() const { return _fMultiLine;}
  168. BOOL IsTransparent() const { return _ped->IsTransparent();}
  169. virtual BOOL GetWordWrap() const;
  170. void SetWordWrap(BOOL fNoWrap);
  171. HRESULT GetCachedSize(DWORD *pdwWidth, DWORD *pdwHeight);
  172. // maximum height and width
  173. virtual LONG GetMaxWidth() const = 0;
  174. virtual LONG GetMaxHeight() const = 0;
  175. virtual LONG GetMaxPixelWidth() const = 0;
  176. // Width, height and line count (all text)
  177. virtual LONG GetWidth() const = 0;
  178. virtual LONG GetHeight() const = 0;
  179. virtual LONG GetResizeHeight() const = 0;
  180. virtual LONG LineCount() const = 0;
  181. // View rectangle
  182. void GetViewRect(RECT &rcView, LPCRECT prcClient = NULL);
  183. LONG GetViewWidth() const { return _xWidthView;}
  184. LONG GetViewHeight() const { return _yHeightView;}
  185. // Visible view properties
  186. virtual LONG GetCliVisible(
  187. LONG *pcpMostVisible = NULL,
  188. BOOL fLastCharOfLastVisible = FALSE) const = 0;
  189. LONG GetFirstVisibleCp() const {return _cpFirstVisible;};
  190. virtual LONG GetFirstVisibleLine() const = 0;
  191. // Line info
  192. virtual LONG GetLineText(LONG ili, TCHAR *pchBuff, LONG cchMost) = 0;
  193. virtual LONG CpFromLine(LONG ili, LONG *pyLine = NULL) = 0;
  194. virtual LONG LineFromCp(LONG cp, BOOL fAtEnd) = 0;
  195. // Point <-> cp conversion
  196. virtual LONG CpFromPoint(POINT pt,
  197. const RECT *prcClient,
  198. CRchTxtPtr * const ptp,
  199. CLinePtr * const prp,
  200. BOOL fAllowEOL,
  201. HITTEST *pHit = NULL,
  202. CDispDim *pdispdim = NULL,
  203. LONG *pcpActual = NULL) = 0;
  204. virtual LONG PointFromTp (
  205. const CRchTxtPtr &tp,
  206. const RECT *prcClient,
  207. BOOL fAtEnd,
  208. POINT &pt,
  209. CLinePtr * const prp,
  210. UINT taMode,
  211. CDispDim *pdispdim = NULL) = 0;
  212. // View recalc and updating
  213. void SetUpdateCaret() {_fUpdateCaret = TRUE;}
  214. void SetViewChanged() {_fViewChanged = TRUE;}
  215. void InvalidateRecalc() {_fNeedRecalc = TRUE;}
  216. BOOL RecalcView (const RECT &rcView, RECT* prcClient = NULL);
  217. BOOL UpdateView();
  218. virtual BOOL UpdateView(const CRchTxtPtr &tpFirst, LONG cchOld, LONG cchNew) = 0;
  219. // Rendering
  220. HRESULT Draw(HDC hicTargetDev,
  221. HDC hdcDraw,
  222. LPCRECT prcClient,
  223. LPCRECT prcWBounds,
  224. LPCRECT prcUpdate,
  225. BOOL (CALLBACK * pfnContinue) (DWORD),
  226. DWORD dwContinue);
  227. // Background recalc
  228. virtual void StepBackgroundRecalc();
  229. virtual BOOL WaitForRecalc(LONG cpMax, LONG yMax);
  230. virtual BOOL WaitForRecalcIli(LONG ili);
  231. virtual BOOL WaitForRecalcView();
  232. // Scrolling
  233. LONG GetXScroll() const {return _xScroll;}
  234. virtual LONG GetYScroll() const {return 0;}
  235. void HScroll(WORD wCode, LONG xPos);
  236. virtual LRESULT VScroll(WORD wCode, LONG yPos);
  237. virtual void LineScroll(LONG cli, LONG cch);
  238. virtual void FractionalScrollView ( LONG yDelta );
  239. virtual void ScrollToLineStart(LONG iDirection);
  240. virtual LONG CalcYLineScrollDelta ( LONG cli, BOOL fFractionalFirst );
  241. BOOL DragScroll(const POINT * ppt); // outside of client rect.
  242. BOOL AutoScroll( POINT pt, const WORD xScrollInset, const WORD yScrollInset );
  243. virtual BOOL ScrollView(LONG xScroll, LONG yScroll, BOOL fTracking, BOOL fFractionalScroll) = 0;
  244. virtual LONG AdjustToDisplayLastLine(LONG yBase, LONG yScroll);
  245. // Smooth Scrolling
  246. void SmoothVScroll ( int direction, WORD cLines, int speedNum, int speedDenom, BOOL fMouseRoller );
  247. void SmoothVScrollUpdate();
  248. BOOL CheckInstallSmoothVScroll();
  249. void CheckRemoveSmoothVScroll();
  250. void FinishSmoothVScroll();
  251. BOOL IsSmoothVScolling() { return _fSmoothVScroll; }
  252. // Scrollbars
  253. virtual LONG GetScrollRange(INT nBar) const;
  254. BOOL IsHScrollEnabled();
  255. BOOL IsVScrollEnabled() {return _fVScrollEnabled; }
  256. // Resizing
  257. void OnClientRectChange(const RECT &rcClient);
  258. void OnViewRectChange(const RECT &rcView);
  259. HRESULT RequestResize();
  260. // Selection
  261. virtual BOOL InvertRange(LONG cp,
  262. LONG cch,
  263. SELDISPLAYACTION selAction) = 0;
  264. // Natural size calculation
  265. virtual HRESULT GetNaturalSize(
  266. HDC hdcDraw,
  267. HDC hicTarget,
  268. DWORD dwMode,
  269. LONG *pwidth,
  270. LONG *pheight) = 0;
  271. LONG GetZoomDenominator() const;
  272. LONG GetZoomNumerator() const;
  273. LONG Zoom(LONG x) const;
  274. LONG UnZoom(LONG x) const;
  275. LONG HimetricXtoDX(LONG xHimetric) const;
  276. LONG HimetricYtoDY(LONG yHimetric) const;
  277. LONG DXtoHimetricX(LONG dx) const;
  278. LONG DYtoHimetricY(LONG dy) const;
  279. void ReDrawOnRectChange(HDC hicTarget, const RECT *prcClient);
  280. HRESULT TransparentHitTest(
  281. HDC hdc,
  282. LPCRECT prcClient,
  283. POINT pt,
  284. DWORD *pHitResult);
  285. HRESULT RoundToLine(HDC hdc, LONG width, LONG *pheight);
  286. void SetTempZoomDenominator(LONG lZoomDenominator)
  287. {
  288. _lTempZoomDenominator = lZoomDenominator;
  289. }
  290. LONG GetTempZoomDenominator()
  291. {
  292. return _lTempZoomDenominator;
  293. }
  294. void ResetTempZoomDenominator()
  295. {
  296. _lTempZoomDenominator = INVALID_ZOOM_DENOMINATOR;
  297. }
  298. void SetDrawInfo(
  299. CDrawInfo *pdi,
  300. DWORD dwDrawAspect, //@parm draw aspect
  301. LONG lindex, //@parm currently unused
  302. void *pvAspect, //@parm info for drawing optimizations (OCX 96)
  303. DVTARGETDEVICE *ptd,//@parm information on target device
  304. HDC hicTargetDev); //@parm target information context
  305. void ReleaseDrawInfo();
  306. void ResetDrawInfo(const CDisplay *pdp);
  307. DWORD GetDrawAspect() const;
  308. LONG GetLindex() const;
  309. void * GetAspect() const;
  310. DVTARGETDEVICE *GetPtd() const;
  311. void SetActiveFlag(BOOL fActive) { _fActive = fActive; }
  312. BOOL IsActive() { return _fActive; }
  313. virtual CDisplay *Clone() const = 0;
  314. // Support for freezing the display
  315. BOOL IsFrozen();
  316. void SaveUpdateCaret(BOOL fScrollIntoView);
  317. void Freeze();
  318. void SetNeedRedisplayOnThaw(BOOL fNeedRedisplay);
  319. void Thaw();
  320. //
  321. // ITxNotify Interface
  322. //
  323. virtual void OnPreReplaceRange(
  324. LONG cp,
  325. LONG cchDel,
  326. LONG cchNew,
  327. LONG cpFormatMin, LONG cpFormatMax);
  328. virtual void OnPostReplaceRange(
  329. LONG cp,
  330. LONG cchDel,
  331. LONG cchNew,
  332. LONG cpFormatMin,
  333. LONG cpFormatMax);
  334. virtual void Zombie();
  335. };
  336. // Defines the draw info class. It is included here to prevent loops
  337. // in dependencies that would require no inlining for functions dealing
  338. // with this
  339. #include "_drwinfo.h"
  340. /*
  341. * CDisplay::ResetDrawInfo
  342. *
  343. * @mfunc Sets draw info using different display
  344. *
  345. * @rdesc void
  346. *
  347. */
  348. inline void CDisplay::ResetDrawInfo(
  349. const CDisplay *pdp) //@parm Display to use for draw information
  350. {
  351. _pdi = pdp->_pdi;
  352. }
  353. /*
  354. * CDisplay::ResetDrawInfo
  355. *
  356. * @mfunc Gets lindex as passed most recently from the host.
  357. *
  358. * @rdesc draw aspect
  359. *
  360. */
  361. inline DWORD CDisplay::GetDrawAspect() const
  362. {
  363. return _pdi ? _pdi->GetDrawAspect() : DVASPECT_CONTENT;
  364. }
  365. /*
  366. * CDisplay::GetLindex
  367. *
  368. * @mfunc Gets lindex as passed most recently from the host.
  369. *
  370. * @rdesc lindex
  371. *
  372. */
  373. inline LONG CDisplay::GetLindex() const
  374. {
  375. return _pdi ? _pdi->GetLindex() : -1;
  376. }
  377. /*
  378. * CDisplay::GetAspect
  379. *
  380. * @mfunc Gets aspect as passed most recently from the host.
  381. *
  382. * @rdesc Aspect data
  383. *
  384. */
  385. inline void *CDisplay::GetAspect() const
  386. {
  387. return _pdi ? _pdi->GetAspect() : NULL;
  388. }
  389. /*
  390. * CDisplay::GetPtd
  391. *
  392. * @mfunc Gets device target as passed most recently from the host.
  393. *
  394. * @rdesc DVTARGETDEVICE or NULL
  395. *
  396. */
  397. inline DVTARGETDEVICE *CDisplay::GetPtd() const
  398. {
  399. return _pdi ? _pdi->GetPtd() : NULL;
  400. }
  401. /*
  402. * CDisplay::IsFrozen
  403. *
  404. * @mfunc Return whether display is currently frozen
  405. *
  406. * @rdesc
  407. * TRUE - display is frozen <nl>
  408. * FALSE - display is not frozen
  409. *
  410. */
  411. inline BOOL CDisplay::IsFrozen()
  412. {
  413. return _padc != NULL;
  414. }
  415. /*
  416. * CFreezeDisplay
  417. *
  418. * @class This class is used to freeze and guranatee that the display
  419. * unfreeze a display when it passes out of its context.
  420. *
  421. *
  422. */
  423. class CFreezeDisplay
  424. {
  425. public:
  426. CFreezeDisplay(CDisplay *pdp); //@cmember Constructor Freezes
  427. ~CFreezeDisplay(); //@cmember Destructor - Thaws
  428. private:
  429. CDisplay * _pdp; //@cmember Display to freeze
  430. };
  431. /*
  432. * CFreezeDisplay::CFreezeDisplay()
  433. *
  434. * @mfunc
  435. * Initialize object and tell the input display to freeze
  436. */
  437. inline CFreezeDisplay::CFreezeDisplay(CDisplay *pdp) : _pdp(pdp)
  438. {
  439. pdp->Freeze();
  440. }
  441. /*
  442. * CFreezeDisplay::CFreezeDisplay()
  443. *
  444. * @mfunc
  445. * Free object and tell display to thaw.
  446. */
  447. inline CFreezeDisplay::~CFreezeDisplay()
  448. {
  449. _pdp->Thaw();
  450. }
  451. #endif