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