]>
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _OGLSAMPLE_DOC_H_ | |
13 | #define _OGLSAMPLE_DOC_H_ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | // #pragma interface | |
17 | #endif | |
18 | ||
19 | #include <wx/docview.h> | |
20 | #include <wx/string.h> | |
21 | #include <wx/wxexpr.h> | |
22 | ||
23 | #include <wx/ogl/ogl.h> | |
24 | ||
25 | #if wxUSE_STD_IOSTREAM | |
dd107c50 | 26 | #include <iosfwd> |
1fc25a89 JS |
27 | #endif |
28 | ||
29 | /* | |
30 | * Override a few members for this application | |
31 | */ | |
32 | ||
33 | class MyDiagram: public wxDiagram | |
34 | { | |
35 | public: | |
36 | MyDiagram(void) {} | |
37 | bool OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr); | |
38 | bool OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr); | |
39 | }; | |
40 | ||
41 | /* | |
42 | * A few new shape classes so we have a 1:1 mapping | |
43 | * between palette symbol and unique class | |
44 | */ | |
45 | ||
46 | class wxRoundedRectangleShape: public wxRectangleShape | |
47 | { | |
48 | DECLARE_DYNAMIC_CLASS(wxRoundedRectangleShape) | |
49 | private: | |
50 | public: | |
51 | wxRoundedRectangleShape(double w = 0.0, double h = 0.0); | |
52 | }; | |
53 | ||
54 | class wxDiamondShape: public wxPolygonShape | |
55 | { | |
56 | DECLARE_DYNAMIC_CLASS(wxDiamondShape) | |
57 | private: | |
58 | public: | |
59 | wxDiamondShape(double w = 0.0, double h = 0.0); | |
60 | }; | |
61 | ||
62 | /* | |
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. | |
65 | */ | |
66 | ||
67 | class MyEvtHandler: public wxShapeEvtHandler | |
68 | { | |
69 | public: | |
70 | wxString label; | |
71 | MyEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL, const wxString& lab = ""):wxShapeEvtHandler(prev, shape) | |
72 | { | |
73 | label = lab; | |
74 | } | |
75 | ~MyEvtHandler(void) | |
76 | { | |
77 | } | |
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); | |
83 | }; | |
84 | ||
85 | /* | |
86 | * A diagram document, which contains a diagram. | |
87 | */ | |
88 | ||
89 | class DiagramDocument: public wxDocument | |
90 | { | |
91 | DECLARE_DYNAMIC_CLASS(DiagramDocument) | |
92 | private: | |
93 | public: | |
94 | MyDiagram diagram; | |
95 | ||
96 | DiagramDocument(void); | |
97 | ~DiagramDocument(void); | |
98 | ||
99 | #if wxUSE_STD_IOSTREAM | |
dd107c50 VZ |
100 | virtual wxSTD ostream& SaveObject(wxSTD ostream& stream); |
101 | virtual wxSTD istream& LoadObject(wxSTD istream& stream); | |
1fc25a89 JS |
102 | #else |
103 | virtual wxOutputStream& SaveObject(wxOutputStream& stream); | |
104 | virtual wxInputStream& LoadObject(wxInputStream& stream); | |
105 | #endif | |
106 | ||
107 | inline wxDiagram *GetDiagram() { return &diagram; } | |
108 | ||
109 | bool OnCloseDocument(void); | |
110 | }; | |
111 | ||
112 | /* | |
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. | |
120 | * | |
121 | * - In 'Do': | |
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'. | |
125 | * - In 'Undo': | |
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'. | |
129 | * | |
130 | * So, as long as we have a pointer to the shape being changed, | |
131 | * we only need one member variable for each property. | |
132 | * | |
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 | |
135 | * when we recreate. | |
136 | */ | |
137 | ||
138 | class DiagramCommand: public wxCommand | |
139 | { | |
140 | protected: | |
141 | DiagramDocument *doc; | |
142 | int cmd; | |
143 | wxShape *shape; // Pointer to the shape we're acting on | |
144 | wxShape *fromShape; | |
145 | wxShape *toShape; | |
146 | wxClassInfo *shapeInfo; | |
147 | double x; | |
148 | double y; | |
149 | bool selected; | |
150 | bool deleteShape; | |
151 | ||
152 | // Storage for property commands | |
153 | wxBrush *shapeBrush; | |
154 | wxPen *shapePen; | |
155 | wxString shapeLabel; | |
156 | public: | |
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); | |
160 | ||
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); | |
164 | ||
165 | ~DiagramCommand(void); | |
166 | ||
167 | bool Do(void); | |
168 | bool Undo(void); | |
169 | ||
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; } | |
176 | ||
177 | void RemoveLines(wxShape *shape); | |
178 | }; | |
179 | ||
180 | #endif | |
181 | // _OGLSAMPLE_DOC_H_ |