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