]> git.saurik.com Git - wxWidgets.git/blob - utils/ogl/src/composit.h
eac0eff62ac506b96a27b21ba5bf5c8cf86de659
[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(wxCompositeShape& copy);
89 wxShape *PrivateCopy();
90
91 virtual wxDivisionShape *OnCreateDivision();
92
93 // Finds the image used to visualize a container. This is any child
94 // of the composite that is not in the divisions list.
95 wxShape *FindContainerImage();
96
97 // Returns TRUE if division is a descendant of this container
98 bool ContainsDivision(wxDivisionShape *division);
99
100 inline wxList& GetDivisions() const { return (wxList&) m_divisions; }
101 inline wxList& GetConstraints() const { return (wxList&) m_constraints; }
102
103 protected:
104 float m_oldX;
105 float m_oldY;
106 wxList m_constraints;
107 wxList m_divisions; // In case it's a container
108 };
109
110 /*
111 * A division object is a composite with special properties,
112 * to be used for containment. It's a subdivision of a container.
113 * A containing node image consists of a composite with a main child shape
114 * such as rounded rectangle, plus a list of division objects.
115 * It needs to be a composite because a division contains pieces
116 * of diagram.
117 * NOTE a container has at least one wxDivisionShape for consistency.
118 * This can be subdivided, so it turns into two objects, then each of
119 * these can be subdivided, etc.
120 */
121 #define DIVISION_SIDE_NONE 0
122 #define DIVISION_SIDE_LEFT 1
123 #define DIVISION_SIDE_TOP 2
124 #define DIVISION_SIDE_RIGHT 3
125 #define DIVISION_SIDE_BOTTOM 4
126
127 class wxDivisionShape: public wxCompositeShape
128 {
129 DECLARE_DYNAMIC_CLASS(wxDivisionShape)
130 public:
131
132 wxDivisionShape();
133 ~wxDivisionShape();
134
135 void OnDraw(wxDC& dc);
136 void OnDrawContents(wxDC& dc);
137 bool OnMovePre(wxDC& dc, float x, float y, float oldX, float oldY, bool display = TRUE);
138 void OnDragLeft(bool draw, float x, float y, int keys, int attachment = 0);
139 void OnBeginDragLeft(float x, float y, int keys, int attachment = 0);
140 void OnEndDragLeft(float x, float y, int keys, int attachment = 0);
141
142 void OnRightClick(float x, float y, int keys = 0, int attachment = 0);
143
144 // Don't want this kind of composite to resize its subdiagrams, so
145 // override composite's SetSize.
146 void SetSize(float w, float h, bool recursive = TRUE);
147
148 // Similarly for calculating size: it's fixed at whatever SetSize
149 // set it to, not in terms of children.
150 void CalculateSize();
151
152 void MakeControlPoints();
153 void ResetControlPoints();
154 void MakeMandatoryControlPoints();
155 void ResetMandatoryControlPoints();
156
157 #ifdef PROLOGIO
158 // Prolog database stuff
159 void WritePrologAttributes(wxExpr *clause);
160 void ReadPrologAttributes(wxExpr *clause);
161 #endif
162 // Does the copying for this object
163 void Copy(wxDivisionShape& copy);
164 wxShape *PrivateCopy();
165
166 // Divide horizontally (wxHORIZONTAL) or vertically (wxVERTICAL)
167 bool Divide(int direction);
168
169 // Resize adjoining divisions at the given side. If test is TRUE,
170 // just see whether it's possible for each adjoining region,
171 // returning FALSE if it's not.
172 bool ResizeAdjoining(int side, float newPos, bool test);
173
174 // Adjust a side, returning FALSE if it's not physically possible.
175 bool AdjustLeft(float left, bool test);
176 bool AdjustTop(float top, bool test);
177 bool AdjustRight(float right, bool test);
178 bool AdjustBottom(float bottom, bool test);
179
180 // Edit style of left or top side
181 void EditEdge(int side);
182
183 // Popup menu
184 void PopupMenu(float x, float y);
185
186 inline void SetLeftSide(wxDivisionShape *shape) { m_leftSide = shape; }
187 inline void SetTopSide(wxDivisionShape *shape) { m_topSide = shape; }
188 inline void SetRightSide(wxDivisionShape *shape) { m_rightSide = shape; }
189 inline void SetBottomSide(wxDivisionShape *shape) { m_bottomSide = shape; }
190 inline wxDivisionShape *GetLeftSide() const { return m_leftSide; }
191 inline wxDivisionShape *GetTopSide() const { return m_topSide; }
192 inline wxDivisionShape *GetRightSide() const { return m_rightSide; }
193 inline wxDivisionShape *GetBottomSide() const { return m_bottomSide; }
194
195 inline void SetHandleSide(int side) { m_handleSide = side; }
196 inline int GetHandleSide() const { return m_handleSide; }
197
198 inline void SetLeftSidePen(wxPen *pen) { m_leftSidePen = pen; }
199 inline wxPen *GetLeftSidePen() const { return m_leftSidePen; }
200 inline void SetTopSidePen(wxPen *pen) { m_topSidePen = pen; }
201 inline wxPen *GetTopSidePen() const { return m_topSidePen; }
202
203 void SetLeftSideColour(const wxString& colour);
204 void SetTopSideColour(const wxString& colour);
205 void SetLeftSideStyle(const wxString& style);
206 void SetTopSideStyle(const wxString& style);
207
208 inline wxString GetLeftSideColour() const { return m_leftSideColour; }
209 inline wxString GetTopSideColour() const { return m_topSideColour; }
210 inline wxString GetLeftSideStyle() const { return m_leftSideStyle; }
211 inline wxString GetTopSideStyle() const { return m_topSideStyle; }
212
213 protected:
214 // Adjoining divisions. NULL indicates edge
215 // of container, and that side shouldn't be
216 // drawn.
217 wxDivisionShape* m_leftSide;
218 wxDivisionShape* m_rightSide;
219 wxDivisionShape* m_topSide;
220 wxDivisionShape* m_bottomSide;
221
222 int m_handleSide; // Side at which handle is legal
223
224 wxPen* m_leftSidePen;
225 wxPen* m_topSidePen;
226 wxString m_leftSideColour;
227 wxString m_topSideColour;
228 wxString m_leftSideStyle;
229 wxString m_topSideStyle;
230 };
231
232 extern wxMenu *oglPopupDivisionMenu;
233 extern void oglGraphicsDivisionMenuProc(wxMenu& menu, wxCommandEvent& event);
234
235 #define DIVISION_MENU_SPLIT_HORIZONTALLY 1
236 #define DIVISION_MENU_SPLIT_VERTICALLY 2
237 #define DIVISION_MENU_EDIT_LEFT_EDGE 3
238 #define DIVISION_MENU_EDIT_TOP_EDGE 4
239 #define DIVISION_MENU_EDIT_RIGHT_EDGE 5
240 #define DIVISION_MENU_EDIT_BOTTOM_EDGE 6
241 #define DIVISION_MENU_DELETE_ALL 7
242
243 #endif
244 // _OGL_COMPOSIT_H_