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

  1. // drawobj.h - interface for CDrawObj and derivatives
  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. #ifndef __DRAWOBJ_H__
  15. #define __DRAWOBJ_H__
  16.  
  17. class CDrawView;
  18. class CDrawDoc;
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CDrawObj - base class for all 'drawable objects'
  22.  
  23. class CDrawObj : public CObject
  24. {
  25. protected:
  26.     DECLARE_SERIAL(CDrawObj);
  27.     CDrawObj();
  28.  
  29. // Constructors
  30. public:
  31.     CDrawObj(const CRect& position);
  32.  
  33. // Attributes
  34.     CRect m_position;
  35.     CDrawDoc* m_pDocument;
  36.  
  37.     virtual int GetHandleCount();
  38.     virtual CPoint GetHandle(int nHandle);
  39.     CRect GetHandleRect(int nHandleID, CDrawView* pView);
  40.     virtual HCURSOR GetHandleCursor(int nHandle);
  41.     virtual void SetLineColor(COLORREF color);
  42.     virtual void SetFillColor(COLORREF color);
  43.  
  44. // Operations
  45.     virtual void Draw(CDC* pDC);
  46.     enum TrackerState { normal, selected, active };
  47.     virtual void DrawTracker(CDC* pDC, TrackerState state);
  48.     virtual void MoveTo(const CRect& positon, CDrawView* pView = NULL);
  49.     virtual int HitTest(CPoint point, CDrawView* pView, BOOL bSelected);
  50.     virtual BOOL Intersects(const CRect& rect);
  51.     virtual void MoveHandleTo(int nHandle, CPoint point, CDrawView* pView = NULL);
  52.     virtual void OnOpen(CDrawView* pView);
  53.     virtual void OnEditProperties();
  54.     virtual CDrawObj* Clone(CDrawDoc* pDoc = NULL);
  55.     virtual void Remove();
  56.     void Invalidate();
  57.  
  58. // Implementation
  59. public:
  60.     virtual ~CDrawObj();
  61.     virtual void Serialize(CArchive& ar);
  62. #ifdef _DEBUG
  63.     void AssertValid();
  64. #endif
  65.  
  66.     // implementation data
  67. protected:
  68.     BOOL m_bPen;
  69.     LOGPEN m_logpen;
  70.     BOOL m_bBrush;
  71.     LOGBRUSH m_logbrush;
  72. };
  73.  
  74. // special 'list' class for this application (requires afxtempl.h)
  75. typedef CTypedPtrList<CObList, CDrawObj*> CDrawObjList;
  76.  
  77. ////////////////////////////////////////////////////////////////////////
  78. // specialized draw objects
  79.  
  80. class CDrawRect : public CDrawObj
  81. {
  82. protected:
  83.     DECLARE_SERIAL(CDrawRect);
  84.     CDrawRect();
  85.  
  86. public:
  87.     CDrawRect(const CRect& position);
  88.  
  89. // Implementation
  90. public:
  91.     virtual void Serialize(CArchive& ar);
  92.     virtual void Draw(CDC* pDC);
  93.     virtual int GetHandleCount();
  94.     virtual CPoint GetHandle(int nHandle);
  95.     virtual HCURSOR GetHandleCursor(int nHandle);
  96.     virtual void MoveHandleTo(int nHandle, CPoint point, CDrawView* pView = NULL);
  97.     virtual BOOL Intersects(const CRect& rect);
  98.     virtual CDrawObj* Clone(CDrawDoc* pDoc);
  99.  
  100. protected:
  101.     enum Shape { rectangle, roundRectangle, ellipse, line };
  102.     Shape m_nShape;
  103.     CPoint m_roundness; // for roundRect corners
  104.  
  105.     friend class CRectTool;
  106. };
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109.  
  110. class CDrawPoly;
  111.  
  112. class CDrawPoly : public CDrawObj
  113. {
  114. protected:
  115.     DECLARE_SERIAL(CDrawPoly);
  116.     CDrawPoly();
  117.  
  118. public:
  119.     CDrawPoly(const CRect& position);
  120.  
  121. // Operations
  122.     void AddPoint(const CPoint& point, CDrawView* pView = NULL);
  123.     BOOL RecalcBounds(CDrawView* pView = NULL);
  124.  
  125. // Implementation
  126. public:
  127.     virtual ~CDrawPoly();
  128.     virtual void Serialize(CArchive& ar);
  129.     virtual void Draw(CDC* pDC);
  130.     virtual void MoveTo(const CRect& position, CDrawView* pView = NULL);
  131.     virtual int GetHandleCount();
  132.     virtual CPoint GetHandle(int nHandle);
  133.     virtual HCURSOR GetHandleCursor(int nHandle);
  134.     virtual void MoveHandleTo(int nHandle, CPoint point, CDrawView* pView = NULL);
  135.     virtual BOOL Intersects(const CRect& rect);
  136.     virtual CDrawObj* Clone(CDrawDoc* pDoc);
  137.  
  138. protected:
  139.     int m_nPoints;
  140.     int m_nAllocPoints;
  141.     CPoint* m_points;
  142.     CDrawPoly* m_pDrawObj;
  143.  
  144.     friend class CPolyTool;
  145. };
  146.  
  147. class CDrawItem;    // COleClientItem derived class
  148.  
  149. class CDrawOleObj : public CDrawObj
  150. {
  151. protected:
  152.     DECLARE_SERIAL(CDrawOleObj);
  153.     CDrawOleObj();
  154.  
  155. public:
  156.     CDrawOleObj(const CRect& position);
  157.  
  158. // Implementation
  159. public:
  160.     virtual void Serialize(CArchive& ar);
  161.     virtual void Draw(CDC* pDC);
  162.     virtual CDrawObj* Clone(CDrawDoc* pDoc);
  163.     virtual void OnOpen(CDrawView* pView);
  164.     virtual void MoveTo(const CRect& positon, CDrawView* pView = NULL);
  165.     virtual void OnEditProperties();
  166.     virtual void Remove();
  167.     virtual ~CDrawOleObj();
  168.  
  169.     static BOOL c_bShowItems;
  170.  
  171.     CDrawItem* m_pClientItem;
  172.     CSize m_extent; // current extent is tracked separate from scaled position
  173. };
  174.  
  175. #endif // __DRAWOBJ_H__
  176.