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