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