]> git.saurik.com Git - wxWidgets.git/blob - utils/ogl/src/composit.h
spurious error messages from wxRegKey::HasValue() suppressed
[wxWidgets.git] / utils / ogl / src / composit.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: composit.h
3 // Purpose: wxCompositeShape
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 _OGL_COMPOSIT_H_
13 #define _OGL_COMPOSIT_H_
14
15 #ifdef __GNUG__
16 #pragma interface "composit.h"
17 #endif
18
19 class wxDivisionShape;
20 class OGLConstraint;
21
22 /*
23 * A composite object is an invisible rectangle surrounding all children
24 *
25 */
26
27 class wxCompositeShape: public wxRectangleShape
28 {
29 DECLARE_DYNAMIC_CLASS(wxCompositeShape)
30 public:
31
32 wxCompositeShape();
33 ~wxCompositeShape();
34
35 void OnDraw(wxDC& dc);
36 void OnDrawContents(wxDC& dc);
37 void OnErase(wxDC& dc);
38 bool OnMovePre(wxDC& dc, float x, float y, float oldX, float oldY, bool display = TRUE);
39 void OnDragLeft(bool draw, float x, float y, int keys, int attachment = 0);
40 void OnBeginDragLeft(float x, float y, int keys, int attachment = 0);
41 void OnEndDragLeft(float x, float y, int keys, int attachment = 0);
42
43 void OnRightClick(float x, float y, int keys, int attachment = 0);
44
45 void SetSize(float w, float h, bool recursive = TRUE);
46
47 // Returns TRUE if it settled down
48 bool Recompute();
49
50 // New members
51 void AddChild(wxShape *child, wxShape *addAfter = NULL);
52 void RemoveChild(wxShape *child);
53
54 OGLConstraint *AddConstraint(OGLConstraint *constraint);
55 OGLConstraint *AddConstraint(int type, wxShape *constraining, wxList& constrained);
56 OGLConstraint *AddConstraint(int type, wxShape *constraining, wxShape *constrained);
57
58 void DeleteConstraint(OGLConstraint *constraint);
59
60 // Delete constraints that involve this child.
61 void DeleteConstraintsInvolvingChild(wxShape *child);
62
63 // Remove the image from any constraints involving it, but DON'T
64 // remove any constraints.
65 void RemoveChildFromConstraints(wxShape *child);
66
67 // Find constraint, also returning actual composite the constraint was in,
68 // in case it had to find it recursively.
69 OGLConstraint *FindConstraint(long id, wxCompositeShape **actualComposite = NULL);
70
71 // Returns TRUE if something changed
72 bool Constrain();
73
74 // Make this composite into a container by creating one wxDivisionShape
75 void MakeContainer();
76
77 // Calculates size and position of composite object based on children
78 void CalculateSize();
79
80 #ifdef PROLOGIO
81 // Prolog database stuff
82 void WritePrologAttributes(wxExpr *clause);
83 void ReadPrologAttributes(wxExpr *clause);
84 // In case the object has constraints it needs to read in in a different pass
85 void ReadConstraints(wxExpr *clause, wxExprDatabase *database);
86 #endif
87 // Does the copying for this object
88 void Copy(wxShape& copy);
89
90 virtual wxDivisionShape *OnCreateDivision();
91
92 // Finds the image used to visualize a container. This is any child
93 // of the composite that is not in the divisions list.
94 wxShape *FindContainerImage();
95
96 // Returns TRUE if division is a descendant of this container
97 bool ContainsDivision(wxDivisionShape *division);
98
99 inline wxList& GetDivisions() const { return (wxList&) m_divisions; }
100 inline wxList& GetConstraints() const { return (wxList&) m_constraints; }
101
102 protected:
103 float m_oldX;
104 float m_oldY;
105 wxList m_constraints;
106 wxList m_divisions; // In case it's a container
107 };
108
109 /*
110 * A division object is a composite with special properties,
111 * to be used for containment. It's a subdivision of a container.
112 * A containing node image consists of a composite with a main child shape
113 * such as rounded rectangle, plus a list of division objects.
114 * It needs to be a composite because a division contains pieces
115 * of diagram.
116 * NOTE a container has at least one wxDivisionShape for consistency.
117 * This can be subdivided, so it turns into two objects, then each of
118 * these can be subdivided, etc.
119 */
120 #define DIVISION_SIDE_NONE 0
121 #define DIVISION_SIDE_LEFT 1
122 #define DIVISION_SIDE_TOP 2
123 #define DIVISION_SIDE_RIGHT 3
124 #define DIVISION_SIDE_BOTTOM 4
125
126 class wxDivisionShape: public wxCompositeShape
127 {
128 DECLARE_DYNAMIC_CLASS(wxDivisionShape)
129 public:
130
131 wxDivisionShape();
132 ~wxDivisionShape();
133
134 void OnDraw(wxDC& dc);
135 void OnDrawContents(wxDC& dc);
136 bool OnMovePre(wxDC& dc, float x, float y, float oldX, float oldY, bool display = TRUE);
137 void OnDragLeft(bool draw, float x, float y, int keys, int attachment = 0);
138 void OnBeginDragLeft(float x, float y, int keys, int attachment = 0);
139 void OnEndDragLeft(float x, float y, int keys, int attachment = 0);
140
141 void OnRightClick(float x, float y, int keys = 0, int attachment = 0);
142
143 // Don't want this kind of composite to resize its subdiagrams, so
144 // override composite's SetSize.
145 void SetSize(float w, float h, bool recursive = TRUE);
146
147 // Similarly for calculating size: it's fixed at whatever SetSize
148 // set it to, not in terms of children.
149 void CalculateSize();
150
151 void MakeControlPoints();
152 void ResetControlPoints();
153 void MakeMandatoryControlPoints();
154 void ResetMandatoryControlPoints();
155
156 #ifdef PROLOGIO
157 // Prolog database stuff
158 void WritePrologAttributes(wxExpr *clause);
159 void ReadPrologAttributes(wxExpr *clause);
160 #endif
161 // Does the copying for this object
162 void Copy(wxShape& copy);
163
164 // Divide horizontally (wxHORIZONTAL) or vertically (wxVERTICAL)
165 bool Divide(int direction);
166
167 // Resize adjoining divisions at the given side. If test is TRUE,
168 // just see whether it's possible for each adjoining region,
169 // returning FALSE if it's not.
170 bool ResizeAdjoining(int side, float newPos, bool test);
171
172 // Adjust a side, returning FALSE if it's not physically possible.
173 bool AdjustLeft(float left, bool test);
174 bool AdjustTop(float top, bool test);
175 bool AdjustRight(float right, bool test);
176 bool AdjustBottom(float bottom, bool test);
177
178 // Edit style of left or top side
179 void EditEdge(int side);
180
181 // Popup menu
182 void PopupMenu(float x, float y);
183
184 inline void SetLeftSide(wxDivisionShape *shape) { m_leftSide = shape; }
185 inline void SetTopSide(wxDivisionShape *shape) { m_topSide = shape; }
186 inline void SetRightSide(wxDivisionShape *shape) { m_rightSide = shape; }
187 inline void SetBottomSide(wxDivisionShape *shape) { m_bottomSide = shape; }
188 inline wxDivisionShape *GetLeftSide() const { return m_leftSide; }
189 inline wxDivisionShape *GetTopSide() const { return m_topSide; }
190 inline wxDivisionShape *GetRightSide() const { return m_rightSide; }
191 inline wxDivisionShape *GetBottomSide() const { return m_bottomSide; }
192
193 inline void SetHandleSide(int side) { m_handleSide = side; }
194 inline int GetHandleSide() const { return m_handleSide; }
195
196 inline void SetLeftSidePen(wxPen *pen) { m_leftSidePen = pen; }
197 inline wxPen *GetLeftSidePen() const { return m_leftSidePen; }
198 inline void SetTopSidePen(wxPen *pen) { m_topSidePen = pen; }
199 inline wxPen *GetTopSidePen() const { return m_topSidePen; }
200
201 void SetLeftSideColour(const wxString& colour);
202 void SetTopSideColour(const wxString& colour);
203 void SetLeftSideStyle(const wxString& style);
204 void SetTopSideStyle(const wxString& style);
205
206 inline wxString GetLeftSideColour() const { return m_leftSideColour; }
207 inline wxString GetTopSideColour() const { return m_topSideColour; }
208 inline wxString GetLeftSideStyle() const { return m_leftSideStyle; }
209 inline wxString GetTopSideStyle() const { return m_topSideStyle; }
210
211 protected:
212 // Adjoining divisions. NULL indicates edge
213 // of container, and that side shouldn't be
214 // drawn.
215 wxDivisionShape* m_leftSide;
216 wxDivisionShape* m_rightSide;
217 wxDivisionShape* m_topSide;
218 wxDivisionShape* m_bottomSide;
219
220 int m_handleSide; // Side at which handle is legal
221
222 wxPen* m_leftSidePen;
223 wxPen* m_topSidePen;
224 wxString m_leftSideColour;
225 wxString m_topSideColour;
226 wxString m_leftSideStyle;
227 wxString m_topSideStyle;
228 };
229
230 extern wxMenu *oglPopupDivisionMenu;
231 extern void oglGraphicsDivisionMenuProc(wxMenu& menu, wxCommandEvent& event);
232
233 #define DIVISION_MENU_SPLIT_HORIZONTALLY 1
234 #define DIVISION_MENU_SPLIT_VERTICALLY 2
235 #define DIVISION_MENU_EDIT_LEFT_EDGE 3
236 #define DIVISION_MENU_EDIT_TOP_EDGE 4
237 #define DIVISION_MENU_EDIT_RIGHT_EDGE 5
238 #define DIVISION_MENU_EDIT_BOTTOM_EDGE 6
239 #define DIVISION_MENU_DELETE_ALL 7
240
241 #endif
242 // _OGL_COMPOSIT_H_