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.

201 lines
6.5 KiB

  1. // riched.h : header file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. #ifndef __RULER_H__
  13. #define __RULER_H__
  14. class CWordPadView;
  15. class CWordPadDoc;
  16. class CRulerBar;
  17. // ruler items include left margin, right margin, indent, and tabs
  18. // horz positions in twips -- necessary to avoid rounding errors
  19. // vertical position in pixels
  20. class CRulerItem
  21. {
  22. public:
  23. CRulerItem(UINT nBitmapID = 0);
  24. ~CRulerItem();
  25. virtual BOOL HitTestPix(CPoint pt) { return GetHitRectPix().PtInRect(pt); }
  26. virtual void Draw(CDC& dc);
  27. virtual void SetHorzPosTwips(int nXPos);
  28. virtual void TrackHorzPosTwips(int nXPos, BOOL bOnRuler = TRUE);
  29. virtual void SetVertPos(int nYPos) { m_nYPosPix = nYPos; }
  30. virtual void SetAlignment(int nAlign) {m_nAlignment = nAlign;}
  31. virtual void SetRuler(CRulerBar* pRuler) {m_pRuler = pRuler;}
  32. virtual void SetBounds(int nMin, int nMax) { m_nMin = nMin; m_nMax = nMax; }
  33. int GetMin() { return m_nMin;}
  34. int GetMax() { return m_nMax;}
  35. void Invalidate();
  36. int GetVertPosPix() { return m_nYPosPix;}
  37. int GetHorzPosTwips() { return m_nXPosTwips;}
  38. int GetHorzPosPix();
  39. CRect GetHitRectPix();
  40. void DrawFocusLine();
  41. void SetTrack(BOOL b);
  42. HBITMAP m_hbm;
  43. HBITMAP m_hbmMask;
  44. CSize m_size; // size of item in pixels
  45. // Operations
  46. BOOL LoadMaskedBitmap(LPCTSTR lpszResourceName);
  47. protected:
  48. int m_nYPosPix;
  49. int m_nXPosTwips;
  50. int m_nAlignment;
  51. BOOL m_bTrack;
  52. CRulerBar* m_pRuler;
  53. CRect m_rcTrack;
  54. CDC* m_pDC; // dc used for drawing tracking line
  55. int m_nMin, m_nMax;
  56. };
  57. class CComboRulerItem : public CRulerItem
  58. {
  59. public:
  60. CComboRulerItem(UINT nBitmapID1, UINT nBitmapID2, CRulerItem& item);
  61. virtual BOOL HitTestPix(CPoint pt);
  62. virtual void Draw(CDC& dc);
  63. virtual void SetHorzPosTwips(int nXPos);
  64. virtual void TrackHorzPosTwips(int nXPos, BOOL bOnRuler = TRUE);
  65. virtual void SetVertPos(int nYPos);
  66. virtual void SetAlignment(int nAlign);
  67. virtual void SetRuler(CRulerBar* pRuler);
  68. virtual void SetBounds(int nMin, int nMax);
  69. int GetMin();
  70. int GetMax();
  71. protected:
  72. CRulerItem m_secondary;
  73. CRulerItem& m_link;
  74. BOOL m_bHitPrimary;
  75. };
  76. class CTabRulerItem : public CRulerItem
  77. {
  78. public:
  79. CTabRulerItem() { SetAlignment(TA_LEFT); }
  80. virtual void Draw(CDC& dc) {if (GetHorzPosTwips() != 0) CRulerItem::Draw(dc);}
  81. virtual void TrackHorzPosTwips(int nXPos, BOOL bOnRuler = TRUE);
  82. virtual BOOL HitTestPix(CPoint pt) { return (GetHorzPosTwips() != 0) ? CRulerItem::HitTestPix(pt) : FALSE;}
  83. };
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CRulerBar
  86. class CRulerBar : public CControlBar
  87. {
  88. // Construction
  89. public:
  90. CRulerBar();
  91. ~CRulerBar();
  92. // Operations
  93. public:
  94. virtual BOOL Create(CWnd* pParentWnd, DWORD dwStyle, UINT nID);
  95. protected:
  96. void Update(const PARAFORMAT& pf);
  97. void Update(CSize sizePaper, const CRect& rectMargins);
  98. // Attributes
  99. public:
  100. BOOL m_bDeferInProgress;
  101. CUnit m_unit;
  102. CRulerItem* m_pSelItem;
  103. CFont fnt;
  104. CSize GetBaseUnits();
  105. CComboRulerItem m_leftmargin;
  106. CRulerItem m_indent;
  107. CRulerItem m_rightmargin;
  108. CRulerItem m_tabItem;
  109. CTabRulerItem m_pTabItems[MAX_TAB_STOPS];
  110. CSize m_sizePaper;
  111. CRect m_rectMargin;
  112. int PrintWidth() {return m_sizePaper.cx - m_rectMargin.left -
  113. m_rectMargin.right;}
  114. int m_nTabs;
  115. int m_logx;
  116. int m_nLinePos;
  117. int m_nScroll; // in pixels
  118. CPen penFocusLine;
  119. CPen penBtnHighLight;
  120. CPen penBtnShadow;
  121. CPen penWindowFrame;
  122. CPen penBtnText;
  123. CPen penBtnFace;
  124. CPen penWindowText;
  125. CPen penWindow;
  126. CBrush brushWindow;
  127. CBrush brushBtnFace;
  128. // Implementation
  129. public:
  130. virtual void DoPaint(CDC* pDC);
  131. virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
  132. void ClientToRuler(CPoint& pt) {pt.Offset(-m_cxLeftBorder+m_nScroll, -m_cyTopBorder);}
  133. void ClientToRuler(CRect& rect) {rect.OffsetRect(-m_cxLeftBorder+m_nScroll, -m_cyTopBorder);}
  134. void RulerToClient(CPoint& pt) {pt.Offset(m_cxLeftBorder-m_nScroll, m_cyTopBorder);}
  135. void RulerToClient(CRect& rect) {rect.OffsetRect(m_cxLeftBorder-m_nScroll, m_cyTopBorder);}
  136. int XTwipsToClient(int nT) {return MulDiv(nT, m_logx, 1440) + m_cxLeftBorder - m_nScroll;}
  137. int XClientToTwips(int nC) {return MulDiv(nC - m_cxLeftBorder + m_nScroll, 1440, m_logx);}
  138. int XTwipsToRuler(int nT) {return MulDiv(nT, m_logx, 1440);}
  139. int XRulerToTwips(int nR) {return MulDiv(nR, 1440, m_logx);}
  140. int XRulerToClient(int nR) {return nR + m_cxLeftBorder - m_nScroll;}
  141. int XClientToRuler(int nC) {return nC - m_cxLeftBorder + m_nScroll;}
  142. protected:
  143. virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
  144. void CreateGDIObjects();
  145. void DrawFace(CDC& dc);
  146. void DrawTickMarks(CDC& dC);
  147. void DrawNumbers(CDC& dc, int nInc, int nTPU);
  148. void DrawDiv(CDC& dc, int nInc, int nLargeDiv, int nLength);
  149. void DrawTabs(CDC& dc);
  150. void FillInParaFormat(PARAFORMAT& pf);
  151. void SortTabs();
  152. void SetMarginBounds();
  153. CRulerItem* GetFreeTab();
  154. CView* GetView()
  155. {
  156. ASSERT(GetParent() != NULL);
  157. return ((CFrameWnd*)GetParent())->GetActiveView();
  158. }
  159. CDocument* GetDocument() { return GetView()->GetDocument(); }
  160. CTabRulerItem* GetHitTabPix(CPoint pt);
  161. // Generated message map functions
  162. //{{AFX_MSG(CRulerBar)
  163. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  164. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  165. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  166. afx_msg void OnSysColorChange();
  167. afx_msg void OnWindowPosChanging(WINDOWPOS FAR* lpwndpos);
  168. afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
  169. afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
  170. //}}AFX_MSG
  171. afx_msg LRESULT OnSizeParent(WPARAM wParam, LPARAM lParam);
  172. DECLARE_MESSAGE_MAP()
  173. friend class CRulerItem;
  174. };
  175. inline int CRulerItem::GetHorzPosPix()
  176. { return m_pRuler->XTwipsToRuler(m_nXPosTwips); }
  177. #endif