home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / tutorial / scribble / step7 / scribdoc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.6 KB  |  130 lines

  1. // ScribDoc.h : interface of the CScribbleDoc class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 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.  
  14.  
  15. // Forward declaration of data structure class
  16. class CScribbleItem;
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // class CStroke
  20. //
  21. // A stroke is a series of connected points in the scribble drawing.
  22. // A scribble document may have multiple strokes.
  23.  
  24. class CStroke : public CObject
  25. {
  26. public:
  27.     CStroke(UINT nPenWidth);
  28.  
  29. protected:
  30.     CStroke();
  31.     DECLARE_SERIAL(CStroke)
  32.  
  33. // Attributes
  34. protected:
  35.     UINT                   m_nPenWidth;    // one pen width applies to entire stroke
  36. public:
  37.     CArray<CPoint,CPoint>  m_pointArray;   // series of connected points
  38.     CRect               m_rectBounding; // smallest rect that surrounds all
  39.                                         // of the points in the stroke
  40.                                         // measured in MM_LOENGLISH units
  41.                                         // (0.01 inches, with Y-axis inverted)
  42. public:
  43.     CRect& GetBoundingRect() { return m_rectBounding; }
  44.  
  45. // Operations
  46. public:
  47.     BOOL DrawStroke(CDC* pDC);
  48.     void FinishStroke();
  49.  
  50. public:
  51.     virtual void Serialize(CArchive& ar);
  52. };
  53.  
  54.  
  55.  
  56. class CScribbleDoc : public COleServerDoc
  57. {
  58. protected: // create from serialization only
  59.     CScribbleDoc();
  60.     DECLARE_DYNCREATE(CScribbleDoc)
  61.  
  62. // Attributes
  63. protected:
  64.     // The document keeps track of the current pen width on
  65.     // behalf of all views. We'd like the user interface of
  66.     // Scribble to be such that if the user chooses the Draw
  67.     // Thick Line command, it will apply to all views, not just
  68.     // the view that currently has the focus.
  69.  
  70.     UINT            m_nPenWidth;        // current user-selected pen width
  71.     BOOL            m_bThickPen;        // TRUE if current pen is thick
  72.     UINT            m_nThinWidth;
  73.     UINT            m_nThickWidth;
  74.     CPen            m_penCur;           // pen created according to
  75.                                         // user-selected pen style (width)
  76. public:
  77.     CTypedPtrList<CObList,CStroke*>     m_strokeList;
  78.     CPen*           GetCurrentPen() { return &m_penCur; }
  79.  
  80. protected:
  81.     CSize           m_sizeDoc;
  82. public:
  83.     CSize GetDocSize() { return m_sizeDoc; }
  84.     CScribbleItem* GetEmbeddedItem()
  85.         { return (CScribbleItem*)COleServerDoc::GetEmbeddedItem(); }
  86.  
  87. // Operations
  88. public:
  89.     CStroke* NewStroke();
  90.  
  91. // Overrides
  92.     // ClassWizard generated virtual function overrides
  93.     //{{AFX_VIRTUAL(CScribbleDoc)
  94.     protected:
  95.     virtual COleServerItem* OnGetEmbeddedItem();
  96.     public:
  97.     virtual BOOL OnNewDocument();
  98.     virtual void Serialize(CArchive& ar);
  99.     virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
  100.     virtual void DeleteContents();
  101.     //}}AFX_VIRTUAL
  102.  
  103. // Implementation
  104. protected:
  105.     void ReplacePen();
  106.     void OnSetItemRects(LPCRECT lpPosRect, LPCRECT lpClipRect);
  107.  
  108. public:
  109.     virtual ~CScribbleDoc();
  110. #ifdef _DEBUG
  111.     virtual void AssertValid() const;
  112.     virtual void Dump(CDumpContext& dc) const;
  113. #endif
  114.  
  115. protected:
  116.     void            InitDocument();
  117.  
  118. // Generated message map functions
  119. protected:
  120.     //{{AFX_MSG(CScribbleDoc)
  121.     afx_msg void OnEditClearAll();
  122.     afx_msg void OnPenThickOrThin();
  123.     afx_msg void OnUpdateEditClearAll(CCmdUI* pCmdUI);
  124.     afx_msg void OnUpdatePenThickOrThin(CCmdUI* pCmdUI);
  125.     afx_msg void OnPenWidths();
  126.     afx_msg void OnEditCopy();
  127.     //}}AFX_MSG
  128.     DECLARE_MESSAGE_MAP()
  129. };
  130.