home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / WORDPAD.PAK / RULER.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  6.2 KB  |  203 lines

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