]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/ogledit/doc.h
Fixes after stock gdi changes within core library
[wxWidgets.git] / contrib / samples / ogl / ogledit / doc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: contrib/samples/ogl/ogledit/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 #include "wx/docview.h"
16 #include "wx/cmdproc.h"
17 #include "wx/string.h"
18
19 #include "wx/ogl/ogl.h" // base header of OGL, includes and adjusts wx/deprecated/setup.h
20
21 #if wxUSE_PROLOGIO
22 #include "wx/deprecated/wxexpr.h"
23 #endif
24
25 #include "wx/ogl/ogl.h"
26
27 #if wxUSE_STD_IOSTREAM
28 #include <iosfwd>
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 #if wxUSE_PROLOGIO
40 bool OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
41 bool OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
42 #endif
43 };
44
45 /*
46 * A few new shape classes so we have a 1:1 mapping
47 * between palette symbol and unique class
48 */
49
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 */
70
71 class MyEvtHandler: public wxShapeEvtHandler
72 {
73 public:
74 wxString label;
75 MyEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL, const wxString& lab = wxEmptyString):wxShapeEvtHandler(prev, shape)
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 */
92
93 class DiagramDocument: public wxDocument
94 {
95 DECLARE_DYNAMIC_CLASS(DiagramDocument)
96 private:
97 public:
98 MyDiagram diagram;
99
100 DiagramDocument(void);
101 ~DiagramDocument(void);
102
103 #if wxUSE_STD_IOSTREAM
104 virtual wxSTD ostream& SaveObject(wxSTD ostream& stream);
105 virtual wxSTD istream& LoadObject(wxSTD istream& stream);
106 #else
107 virtual wxOutputStream& SaveObject(wxOutputStream& stream);
108 virtual wxInputStream& LoadObject(wxInputStream& stream);
109 #endif
110
111 inline wxDiagram *GetDiagram() { return &diagram; }
112
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 */
141
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 const wxBrush *shapeBrush;
158 wxPen *shapePen;
159 wxString shapeLabel;
160 public:
161 // Multi-purpose constructor for creating, deleting shapes
162 DiagramCommand(const wxString& name, int cmd, DiagramDocument *ddoc, wxClassInfo *shapeInfo = NULL,
163 double x = 0.0, double y = 0.0, bool sel = false, wxShape *theShape = NULL, wxShape *fs = NULL, wxShape *ts = NULL);
164
165 // Property-changing command constructors
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);
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_