]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/ogledit/doc.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Document classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _OGLSAMPLE_DOC_H_
13 #define _OGLSAMPLE_DOC_H_
19 #include <wx/docview.h>
20 #include <wx/string.h>
21 #include <wx/wxexpr.h>
23 #include <wx/ogl/ogl.h>
25 #if wxUSE_STD_IOSTREAM
30 * Override a few members for this application
33 class MyDiagram
: public wxDiagram
37 bool OnShapeSave(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
38 bool OnShapeLoad(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
42 * A few new shape classes so we have a 1:1 mapping
43 * between palette symbol and unique class
46 class wxRoundedRectangleShape
: public wxRectangleShape
48 DECLARE_DYNAMIC_CLASS(wxRoundedRectangleShape
)
51 wxRoundedRectangleShape(double w
= 0.0, double h
= 0.0);
54 class wxDiamondShape
: public wxPolygonShape
56 DECLARE_DYNAMIC_CLASS(wxDiamondShape
)
59 wxDiamondShape(double w
= 0.0, double h
= 0.0);
63 * All shape event behaviour is routed through this handler, so we don't
64 * have to derive from each shape class. We plug this in to each shape.
67 class MyEvtHandler
: public wxShapeEvtHandler
71 MyEvtHandler(wxShapeEvtHandler
*prev
= NULL
, wxShape
*shape
= NULL
, const wxString
& lab
= ""):wxShapeEvtHandler(prev
, shape
)
78 void OnLeftClick(double x
, double y
, int keys
= 0, int attachment
= 0);
79 void OnBeginDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
80 void OnDragRight(bool draw
, double x
, double y
, int keys
= 0, int attachment
= 0);
81 void OnEndDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
82 void OnEndSize(double x
, double y
);
86 * A diagram document, which contains a diagram.
89 class DiagramDocument
: public wxDocument
91 DECLARE_DYNAMIC_CLASS(DiagramDocument
)
96 DiagramDocument(void);
97 ~DiagramDocument(void);
99 #if wxUSE_STD_IOSTREAM
100 virtual wxSTD ostream
& SaveObject(wxSTD ostream
& stream
);
101 virtual wxSTD istream
& LoadObject(wxSTD istream
& stream
);
103 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
104 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
107 inline wxDiagram
*GetDiagram() { return &diagram
; }
109 bool OnCloseDocument(void);
113 * Most user interface commands are routed through this, to give us the
114 * Undo/Redo mechanism. If you add more commands, such as changing the shape colour,
115 * you will need to add members to 'remember' what the user applied (for 'Do') and what the
116 * previous state was (for 'Undo').
117 * You can have one member for each property to be changed. Assume we also have
118 * a pointer member wxShape *shape, which is set to the shape being changed.
119 * Let's assume we're changing the shape colour. Our member for this is shapeColour.
122 * o Set a temporary variable 'temp' to the current colour for 'shape'.
123 * o Change the colour to the new colour.
124 * o Set shapeColour to the _old_ colour, 'temp'.
126 * o Set a temporary variable 'temp' to the current colour for 'shape'.
127 * o Change the colour to shapeColour (the old colour).
128 * o Set shapeColour to 'temp'.
130 * So, as long as we have a pointer to the shape being changed,
131 * we only need one member variable for each property.
133 * PROBLEM: when an Add shape command is redone, the 'shape' pointer changes.
134 * Assume, as here, that we keep a pointer to the old shape so we reuse it
138 class DiagramCommand
: public wxCommand
141 DiagramDocument
*doc
;
143 wxShape
*shape
; // Pointer to the shape we're acting on
146 wxClassInfo
*shapeInfo
;
152 // Storage for property commands
157 // Multi-purpose constructor for creating, deleting shapes
158 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, wxClassInfo
*shapeInfo
= NULL
,
159 double x
= 0.0, double y
= 0.0, bool sel
= FALSE
, wxShape
*theShape
= NULL
, wxShape
*fs
= NULL
, wxShape
*ts
= NULL
);
161 // Property-changing command constructors
162 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, wxBrush
*backgroundColour
, wxShape
*theShape
);
163 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, const wxString
& lab
, wxShape
*theShape
);
165 ~DiagramCommand(void);
170 inline void SetShape(wxShape
*s
) { shape
= s
; }
171 inline wxShape
*GetShape(void) { return shape
; }
172 inline wxShape
*GetFromShape(void) { return fromShape
; }
173 inline wxShape
*GetToShape(void) { return toShape
; }
174 inline wxClassInfo
*GetShapeInfo(void) { return shapeInfo
; }
175 inline bool GetSelected(void) { return selected
; }
177 void RemoveLines(wxShape
*shape
);