]>
Commit | Line | Data |
---|---|---|
1fc25a89 JS |
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 | |
2ba06d5a | 9 | // Licence: wxWindows licence |
1fc25a89 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _OGLSAMPLE_DOC_H_ | |
13 | #define _OGLSAMPLE_DOC_H_ | |
14 | ||
ab7ce33c | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
1fc25a89 JS |
16 | // #pragma interface |
17 | #endif | |
18 | ||
19 | #include <wx/docview.h> | |
606b005f | 20 | #include <wx/cmdproc.h> |
1fc25a89 | 21 | #include <wx/string.h> |
1fc25a89 | 22 | |
cecdcad1 | 23 | #include <wx/ogl/ogl.h> // base header of OGL, includes and adjusts wx/deprecated/setup.h |
1dde66dd JS |
24 | |
25 | #if wxUSE_PROLOGIO | |
7c9955d1 | 26 | #include <wx/deprecated/wxexpr.h> |
1dde66dd JS |
27 | #endif |
28 | ||
1fc25a89 JS |
29 | #include <wx/ogl/ogl.h> |
30 | ||
31 | #if wxUSE_STD_IOSTREAM | |
dd107c50 | 32 | #include <iosfwd> |
1fc25a89 JS |
33 | #endif |
34 | ||
35 | /* | |
36 | * Override a few members for this application | |
37 | */ | |
cecdcad1 | 38 | |
1fc25a89 JS |
39 | class MyDiagram: public wxDiagram |
40 | { | |
41 | public: | |
42 | MyDiagram(void) {} | |
1dde66dd | 43 | #if wxUSE_PROLOGIO |
1fc25a89 JS |
44 | bool OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr); |
45 | bool OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr); | |
1dde66dd | 46 | #endif |
1fc25a89 JS |
47 | }; |
48 | ||
49 | /* | |
50 | * A few new shape classes so we have a 1:1 mapping | |
51 | * between palette symbol and unique class | |
52 | */ | |
cecdcad1 | 53 | |
1fc25a89 JS |
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 | */ | |
cecdcad1 | 74 | |
1fc25a89 JS |
75 | class MyEvtHandler: public wxShapeEvtHandler |
76 | { | |
77 | public: | |
78 | wxString label; | |
1484b5cc | 79 | MyEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL, const wxString& lab = wxEmptyString):wxShapeEvtHandler(prev, shape) |
1fc25a89 JS |
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 | */ | |
cecdcad1 | 96 | |
1fc25a89 JS |
97 | class DiagramDocument: public wxDocument |
98 | { | |
99 | DECLARE_DYNAMIC_CLASS(DiagramDocument) | |
100 | private: | |
101 | public: | |
102 | MyDiagram diagram; | |
cecdcad1 | 103 | |
1fc25a89 JS |
104 | DiagramDocument(void); |
105 | ~DiagramDocument(void); | |
106 | ||
107 | #if wxUSE_STD_IOSTREAM | |
dd107c50 VZ |
108 | virtual wxSTD ostream& SaveObject(wxSTD ostream& stream); |
109 | virtual wxSTD istream& LoadObject(wxSTD istream& stream); | |
1fc25a89 JS |
110 | #else |
111 | virtual wxOutputStream& SaveObject(wxOutputStream& stream); | |
112 | virtual wxInputStream& LoadObject(wxInputStream& stream); | |
113 | #endif | |
cecdcad1 | 114 | |
1fc25a89 | 115 | inline wxDiagram *GetDiagram() { return &diagram; } |
cecdcad1 | 116 | |
1fc25a89 JS |
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 | */ | |
cecdcad1 | 145 | |
1fc25a89 JS |
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 | |
1484b5cc | 166 | DiagramCommand(const wxString& name, int cmd, DiagramDocument *ddoc, wxClassInfo *shapeInfo = NULL, |
2ba06d5a | 167 | double x = 0.0, double y = 0.0, bool sel = false, wxShape *theShape = NULL, wxShape *fs = NULL, wxShape *ts = NULL); |
1fc25a89 JS |
168 | |
169 | // Property-changing command constructors | |
1484b5cc VS |
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); | |
1fc25a89 JS |
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_ |