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