home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2233.zip / wxOS2-2_3_3.zip / wxWindows-2.3.3 / contrib / samples / ogl / ogledit / doc.h < prev    next >
C/C++ Source or Header  |  2002-09-08  |  6KB  |  183 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        doc.h
  3. // Purpose:     Document classes
  4. // Author:      Julian Smart
  5. // Modified by:
  6. // Created:     12/07/98
  7. // RCS-ID:      $Id: doc.h,v 1.4 2002/09/07 12:12:21 GD Exp $
  8. // Copyright:   (c) Julian Smart
  9. // Licence:       wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifndef _OGLSAMPLE_DOC_H_
  13. #define _OGLSAMPLE_DOC_H_
  14.  
  15. #if defined(__GNUG__) && !defined(__APPLE__)
  16. // #pragma interface
  17. #endif
  18.  
  19. #include <wx/docview.h>
  20. #include <wx/cmdproc.h>
  21. #include <wx/string.h>
  22. #include <wx/wxexpr.h>
  23.  
  24. #include <wx/ogl/ogl.h>
  25.  
  26. #if wxUSE_STD_IOSTREAM
  27.  #include <iosfwd>
  28. #endif
  29.  
  30. /*
  31.  * Override a few members for this application
  32.  */
  33.  
  34. class MyDiagram: public wxDiagram
  35. {
  36.  public:
  37.   MyDiagram(void) {}
  38.   bool OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
  39.   bool OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
  40. };
  41.  
  42. /*
  43.  * A few new shape classes so we have a 1:1 mapping
  44.  * between palette symbol and unique class
  45.  */
  46.  
  47. class wxRoundedRectangleShape: public wxRectangleShape
  48. {
  49.   DECLARE_DYNAMIC_CLASS(wxRoundedRectangleShape)
  50.  private:
  51.  public:
  52.   wxRoundedRectangleShape(double w = 0.0, double h = 0.0);
  53. };
  54.  
  55. class wxDiamondShape: public wxPolygonShape
  56. {
  57.   DECLARE_DYNAMIC_CLASS(wxDiamondShape)
  58.  private:
  59.  public:
  60.   wxDiamondShape(double w = 0.0, double h = 0.0);
  61. };
  62.  
  63. /*
  64.  * All shape event behaviour is routed through this handler, so we don't
  65.  * have to derive from each shape class. We plug this in to each shape.
  66.  */
  67.  
  68. class MyEvtHandler: public wxShapeEvtHandler
  69. {
  70.  public:
  71.   wxString label;
  72.   MyEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL, const wxString& lab = ""):wxShapeEvtHandler(prev, shape)
  73.   {
  74.     label = lab;
  75.   }
  76.   ~MyEvtHandler(void)
  77.   {
  78.   }
  79.   void OnLeftClick(double x, double y, int keys = 0, int attachment = 0);
  80.   void OnBeginDragRight(double x, double y, int keys = 0, int attachment = 0);
  81.   void OnDragRight(bool draw, double x, double y, int keys = 0, int attachment = 0);
  82.   void OnEndDragRight(double x, double y, int keys = 0, int attachment = 0);
  83.   void OnEndSize(double x, double y);
  84. };
  85.  
  86. /*
  87.  * A diagram document, which contains a diagram.
  88.  */
  89.  
  90. class DiagramDocument: public wxDocument
  91. {
  92.   DECLARE_DYNAMIC_CLASS(DiagramDocument)
  93.  private:
  94.  public:
  95.   MyDiagram diagram;
  96.   
  97.   DiagramDocument(void);
  98.   ~DiagramDocument(void);
  99.  
  100. #if wxUSE_STD_IOSTREAM
  101.     virtual wxSTD ostream& SaveObject(wxSTD ostream& stream);
  102.     virtual wxSTD istream& LoadObject(wxSTD istream& stream);
  103. #else
  104.     virtual wxOutputStream& SaveObject(wxOutputStream& stream);
  105.     virtual wxInputStream& LoadObject(wxInputStream& stream);
  106. #endif
  107.   
  108.   inline wxDiagram *GetDiagram() { return &diagram; }
  109.   
  110.   bool OnCloseDocument(void);
  111. };
  112.  
  113. /*
  114.  * Most user interface commands are routed through this, to give us the
  115.  * Undo/Redo mechanism. If you add more commands, such as changing the shape colour,
  116.  * you will need to add members to 'remember' what the user applied (for 'Do') and what the
  117.  * previous state was (for 'Undo').
  118.  * You can have one member for each property to be changed. Assume we also have
  119.  * a pointer member wxShape *shape, which is set to the shape being changed.
  120.  * Let's assume we're changing the shape colour. Our member for this is shapeColour.
  121.  *
  122.  * - In 'Do':
  123.  *   o Set a temporary variable 'temp' to the current colour for 'shape'.
  124.  *   o Change the colour to the new colour.
  125.  *   o Set shapeColour to the _old_ colour, 'temp'.
  126.  * - In 'Undo':
  127.  *   o Set a temporary variable 'temp' to the current colour for 'shape'.
  128.  *   o Change the colour to shapeColour (the old colour).
  129.  *   o Set shapeColour to 'temp'.
  130.  *
  131.  * So, as long as we have a pointer to the shape being changed,
  132.  * we only need one member variable for each property.
  133.  *
  134.  * PROBLEM: when an Add shape command is redone, the 'shape' pointer changes.
  135.  * Assume, as here, that we keep a pointer to the old shape so we reuse it
  136.  * when we recreate.
  137.  */
  138.  
  139. class DiagramCommand: public wxCommand
  140. {
  141.  protected:
  142.   DiagramDocument *doc;
  143.   int cmd;
  144.   wxShape *shape; // Pointer to the shape we're acting on
  145.   wxShape *fromShape;
  146.   wxShape *toShape;
  147.   wxClassInfo *shapeInfo;
  148.   double x;
  149.   double y;
  150.   bool selected;
  151.   bool deleteShape;
  152.  
  153.   // Storage for property commands
  154.   wxBrush *shapeBrush;
  155.   wxPen *shapePen;
  156.   wxString shapeLabel;
  157.  public:
  158.   // Multi-purpose constructor for creating, deleting shapes
  159.   DiagramCommand(char *name, int cmd, DiagramDocument *ddoc, wxClassInfo *shapeInfo = NULL,
  160.      double x = 0.0, double y = 0.0, bool sel = FALSE, wxShape *theShape = NULL, wxShape *fs = NULL, wxShape *ts = NULL);
  161.  
  162.   // Property-changing command constructors
  163.   DiagramCommand(char *name, int cmd, DiagramDocument *ddoc, wxBrush *backgroundColour, wxShape *theShape);
  164.   DiagramCommand(char *name, int cmd, DiagramDocument *ddoc, const wxString& lab, wxShape *theShape);
  165.  
  166.   ~DiagramCommand(void);
  167.  
  168.   bool Do(void);
  169.   bool Undo(void);
  170.  
  171.   inline void SetShape(wxShape *s) { shape = s; }
  172.   inline wxShape *GetShape(void) { return shape; }
  173.   inline wxShape *GetFromShape(void) { return fromShape; }
  174.   inline wxShape *GetToShape(void) { return toShape; }
  175.   inline wxClassInfo *GetShapeInfo(void) { return shapeInfo; }
  176.   inline bool GetSelected(void) { return selected; }
  177.  
  178.   void RemoveLines(wxShape *shape);
  179. };
  180.  
  181. #endif
  182.   // _OGLSAMPLE_DOC_H_
  183.