]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/studio/shapes.h
src/common/wxchar.cpps/wxConvLocal/wxConvLibs/g as otherwise we may fail to convert...
[wxWidgets.git] / contrib / samples / ogl / studio / shapes.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: shapes.h
3 // Purpose: Shape classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 12/07/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _STUDIO_SHAPES_H_
13 #define _STUDIO_SHAPES_H_
14
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 // #pragma interface
17 #endif
18
19 #include <wx/docview.h>
20 #include <wx/string.h>
21 #include <wx/deprecated/setup.h>
22 #include <wx/deprecated/wxexpr.h>
23
24 #include <wx/ogl/ogl.h>
25 #include <wx/ogl/basicp.h>
26 #include <wx/ogl/linesp.h>
27 #include <wx/ogl/drawn.h>
28
29 class csDiagramDocument;
30
31 /*
32 * Override a few members for this application
33 */
34
35 class csDiagram: public wxDiagram
36 {
37 DECLARE_CLASS(csDiagram)
38 public:
39 csDiagram(csDiagramDocument* doc) { m_doc = doc; }
40 ~csDiagram();
41 bool OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
42 bool OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
43
44 inline csDiagramDocument* GetDocument() const { return m_doc; }
45 virtual void Redraw(wxDC& dc);
46
47 protected:
48 csDiagramDocument* m_doc;
49 };
50
51 class wxDiagramClipboard: public wxDiagram
52 {
53 DECLARE_DYNAMIC_CLASS(wxDiagramClipboard)
54 public:
55 wxDiagramClipboard() {}
56 ~wxDiagramClipboard() {}
57
58 // Copy selection to clipboard
59 bool Copy(wxDiagram* diagram);
60
61 // Copy contents to the diagram, with new ids.
62 // If dc is non-NULL, the pasted shapes will be selected.
63 // The offsets are used to place the shapes at a different position
64 // from the original (for example, for duplicating shapes).
65 bool Paste(wxDiagram* diagram, wxDC* dc = NULL,
66 int offsetX = 0, int offsetY = 0);
67
68 #ifdef __WXMSW__
69 // Draw contents to a Windows metafile device context and bitmap, and then copy
70 // to the Windows clipboard.
71 bool CopyToClipboard(double scale);
72 #endif
73
74 // Overridables
75 // Start/end copying
76 virtual bool OnStartCopy(wxDiagram* WXUNUSED(diagramTo)) { return true; };
77 virtual bool OnEndCopy(wxDiagram* WXUNUSED(diagramTo)) { return true; };
78
79 // Override this to e.g. have the shape added through a Do/Undo command system.
80 // By default, we'll just add it directly to the destination diagram, and
81 // select the shape (if dc is non-NULL).
82 virtual bool OnAddShape(wxDiagram* diagramTo, wxShape* newShape, wxDC* dc);
83
84 protected:
85 bool DoCopy(wxDiagram* diagramFrom, wxDiagram* diagramTo, bool newIds,
86 wxDC* dc, int offsetX = 0, int offsetY = 0);
87
88 };
89
90 class csDiagramCommand;
91
92 class csDiagramClipboard: public wxDiagramClipboard
93 {
94 DECLARE_DYNAMIC_CLASS(csDiagramClipboard)
95 public:
96 csDiagramClipboard() { m_currentCmd = NULL; }
97 ~csDiagramClipboard() {}
98
99 // Start/end copying
100 virtual bool OnStartCopy(wxDiagram* diagramTo);
101 virtual bool OnEndCopy(wxDiagram* diagramTo);
102
103 virtual bool OnAddShape(wxDiagram* diagramTo, wxShape* newShape, wxDC* dc);
104
105 protected:
106 csDiagramCommand* m_currentCmd;
107 };
108
109
110 /*
111 * The Studio shapes
112 * N.B. TODO: these should really all have another constructor
113 * for the ready-initialised shape, with the default one not having any
114 * data. Otherwise when copying a shape, you have to delete the old data
115 * first -> slightly less efficient. The initialised shapes are only required
116 * for the first creation of the shape in the palette, everything else is copied.
117 */
118
119 class csThinRectangleShape: public wxDrawnShape
120 {
121 DECLARE_DYNAMIC_CLASS(csThinRectangleShape)
122 public:
123 csThinRectangleShape();
124 };
125
126 class csWideRectangleShape: public wxDrawnShape
127 {
128 DECLARE_DYNAMIC_CLASS(csWideRectangleShape)
129 public:
130 csWideRectangleShape();
131 };
132
133 class csTriangleShape: public wxDrawnShape
134 {
135 DECLARE_DYNAMIC_CLASS(csTriangleShape)
136 public:
137 csTriangleShape();
138 };
139
140 class csSemiCircleShape: public wxDrawnShape
141 {
142 DECLARE_DYNAMIC_CLASS(csSemiCircleShape)
143 public:
144 csSemiCircleShape();
145 };
146
147 class csCircleShape: public wxCircleShape
148 {
149 DECLARE_DYNAMIC_CLASS(csCircleShape)
150 public:
151 csCircleShape();
152 };
153
154 class csCircleShadowShape: public wxCircleShape
155 {
156 DECLARE_DYNAMIC_CLASS(csCircleShadowShape)
157 public:
158 csCircleShadowShape();
159 };
160
161 class csOctagonShape: public wxPolygonShape
162 {
163 DECLARE_DYNAMIC_CLASS(csOctagonShape)
164 public:
165 csOctagonShape();
166
167 // The attachments are as if it's a rectangle
168 bool GetAttachmentPosition(int attachment, double *x, double *y,
169 int nth = 0, int no_arcs = 1, wxLineShape *line = NULL)
170 { return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line); }
171 int GetNumberOfAttachments() const
172 { return wxShape::GetNumberOfAttachments(); }
173 bool AttachmentIsValid(int attachment) const
174 { return wxShape::AttachmentIsValid(attachment); }
175 };
176
177 // This is a transparent shape for drawing around other shapes.
178 class csGroupShape: public wxRectangleShape
179 {
180 DECLARE_DYNAMIC_CLASS(csGroupShape)
181 public:
182 csGroupShape();
183
184 void OnDraw(wxDC& dc);
185 // Must modify the hit-test so it doesn't obscure shapes that are inside.
186 bool HitTest(double x, double y, int* attachment, double* distance);
187 };
188
189 class csTextBoxShape: public wxRectangleShape
190 {
191 DECLARE_DYNAMIC_CLASS(csTextBoxShape)
192 public:
193 csTextBoxShape();
194 };
195
196 class csLineShape: public wxLineShape
197 {
198 DECLARE_DYNAMIC_CLASS(csLineShape)
199 public:
200 csLineShape();
201
202 virtual bool OnMoveMiddleControlPoint(wxDC& dc, wxLineControlPoint* lpt, const wxRealPoint& pt);
203 wxLabelShape* OnCreateLabelShape(wxLineShape *parent = NULL, wxShapeRegion *region = NULL, double w = 0.0, double h = 0.0);
204 };
205
206 /*
207 * Temporary arc label object
208 */
209
210 class csLabelShape: public wxLabelShape
211 {
212 DECLARE_DYNAMIC_CLASS(csLabelShape)
213
214 public:
215 csLabelShape(wxLineShape *parent = NULL, wxShapeRegion *region = NULL, double w = 0.0, double h = 0.0);
216
217 void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
218 };
219
220 /*
221 * All shape event behaviour is routed through this handler, so we don't
222 * have to derive from each shape class. We plug this in to each shape.
223 */
224
225 class csEvtHandler: public wxShapeEvtHandler
226 {
227 DECLARE_DYNAMIC_CLASS(csEvtHandler)
228 public:
229 csEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL, const wxString& lab = wxEmptyString);
230 ~csEvtHandler();
231
232 void OnLeftClick(double x, double y, int keys = 0, int attachment = 0);
233 void OnRightClick(double x, double y, int keys = 0, int attachment = 0);
234 void OnBeginDragRight(double x, double y, int keys = 0, int attachment = 0);
235 void OnDragRight(bool draw, double x, double y, int keys = 0, int attachment = 0);
236 void OnEndDragRight(double x, double y, int keys = 0, int attachment = 0);
237 void OnEndSize(double x, double y);
238 void OnDragLeft(bool draw, double x, double y, int keys = 0, int attachment = 0);
239 void OnBeginDragLeft(double x, double y, int keys = 0, int attachment = 0);
240 void OnEndDragLeft(double x, double y, int keys = 0, int attachment = 0);
241 void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys = 0, int attachment = 0);
242 void OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering);
243
244 void OnLeftDoubleClick(double x, double y, int keys = 0, int attachment = 0);
245
246 // Copy any event handler data
247 virtual void CopyData(wxShapeEvtHandler& copy);
248
249 // Popup up a property dialog
250 virtual bool EditProperties();
251
252 public:
253 wxString m_label;
254 };
255
256 class ShapeEditMenu: public wxMenu
257 {
258 public:
259 ShapeEditMenu() {}
260
261 void OnCommand(wxCommandEvent& event);
262
263 DECLARE_EVENT_TABLE()
264 };
265
266 extern void studioShapeEditProc(wxMenu& menu, wxCommandEvent& event);
267
268 #endif
269 // _STUDIO_SHAPES_H_