1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxLineShape
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "lines.h"
20 class wxPseudoMetaFile
;
21 class wxLineControlPoint
;
23 * Arcs with multiple arrowheads
29 #define ARROW_HOLLOW_CIRCLE 1
30 #define ARROW_FILLED_CIRCLE 2
32 #define ARROW_SINGLE_OBLIQUE 4
33 #define ARROW_DOUBLE_OBLIQUE 5
35 #define ARROW_METAFILE 20
37 // Position of arrow on line
38 #define ARROW_POSITION_START 0
39 #define ARROW_POSITION_END 1
40 #define ARROW_POSITION_MIDDLE 2
42 // Line alignment flags
43 // Vertical by default
44 #define LINE_ALIGNMENT_HORIZ 1
45 #define LINE_ALIGNMENT_VERT 0
46 #define LINE_ALIGNMENT_TO_NEXT_HANDLE 2
47 #define LINE_ALIGNMENT_NONE 0
49 class wxArrowHead
: public wxObject
51 DECLARE_DYNAMIC_CLASS(wxArrowHead
)
54 wxArrowHead(WXTYPE type
= 0, int end
= 0, double size
= 0.0, double dist
= 0.0, const wxString
& name
= "", wxPseudoMetaFile
*mf
= NULL
,
57 wxArrowHead(wxArrowHead
& toCopy
);
59 inline WXTYPE
_GetType() const { return m_arrowType
; }
60 inline int GetPosition() const { return m_arrowEnd
; }
61 inline void SetPosition(int pos
) { m_arrowEnd
= pos
; }
62 inline double GetXOffset() const { return m_xOffset
; }
63 inline double GetYOffset() const { return m_yOffset
; }
64 inline double GetSpacing() const { return m_spacing
; }
65 inline double GetSize() const { return m_arrowSize
; }
66 inline wxString
GetName() const { return m_arrowName
; }
67 inline void SetXOffset(double x
) { m_xOffset
= x
; }
68 inline void SetYOffset(double y
) { m_yOffset
= y
; }
69 inline wxPseudoMetaFile
*GetMetaFile() const { return m_metaFile
; }
70 inline long GetId() const { return m_id
; }
71 inline int GetArrowEnd() const { return m_arrowEnd
; }
72 inline double GetArrowSize() const { return m_arrowSize
; }
73 void SetSize(double size
);
74 inline void SetSpacing(double sp
) { m_spacing
= sp
; }
78 int m_arrowEnd
; // Position on line
79 double m_xOffset
; // Distance from arc start or end, w.r.t. point on arrowhead
80 // nearest start or end. If zero, use default spacing.
81 double m_yOffset
; // vertical offset (w.r.t. a horizontal line). Normally zero.
82 double m_spacing
; // Spacing from the last arrowhead
83 double m_arrowSize
; // Length of arrowhead
84 wxString m_arrowName
; // Name of arrow
85 bool m_saveToFile
; // TRUE if we want to save custom arrowheads to file.
86 wxPseudoMetaFile
* m_metaFile
; // Pseudo metafile if this is a custom arrowhead
87 long m_id
; // identifier
91 class wxLineShape
: public wxShape
93 DECLARE_DYNAMIC_CLASS(wxLineShape
)
99 // Called when a connected object has moved, to move the link to
101 // moveControlPoints must be disabled when a control point is being
103 void OnMoveLink(wxDC
& dc
, bool moveControlPoints
= TRUE
);
104 bool OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
= TRUE
);
105 void OnDraw(wxDC
& dc
);
106 void OnDrawContents(wxDC
& dc
);
107 void OnDrawControlPoints(wxDC
& dc
);
108 void OnEraseControlPoints(wxDC
& dc
);
109 void OnErase(wxDC
& dc
);
110 virtual inline void OnMoveControlPoint(int WXUNUSED(which
), double WXUNUSED(x
), double WXUNUSED(y
)) {}
111 void OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
);
112 void GetBoundingBoxMin(double *w
, double *h
);
113 void FormatText(wxDC
& dc
, const wxString
& s
, int regionId
= 0);
114 virtual void SetEnds(double x1
, double y1
, double x2
, double y2
);
115 virtual void GetEnds(double *x1
, double *y1
, double *x2
, double *y2
);
116 inline virtual wxShape
*GetFrom() { return m_from
; }
117 inline virtual wxShape
*GetTo() { return m_to
; }
118 inline virtual int GetAttachmentFrom() { return m_attachmentFrom
; }
119 inline virtual int GetAttachmentTo() { return m_attachmentTo
; }
121 virtual void SetFrom(wxShape
*object
);
122 virtual void SetTo(wxShape
*object
);
123 virtual void DrawArrows(wxDC
& dc
);
125 // Finds the x, y points at the two ends of the line.
126 // This function can be used by e.g. line-routing routines to
127 // get the actual points on the two node images where the lines will be drawn
129 void FindLineEndPoints(double *fromX
, double *fromY
, double *toX
, double *toY
);
131 // Format one region at this position
132 void DrawRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
);
134 // Erase one region at this position
135 void EraseRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
);
137 // Get the reference point for a label. Region x and y
138 // are offsets from this.
139 // position is 0 (middle), 1 (start), 2 (end)
140 void GetLabelPosition(int position
, double *x
, double *y
);
142 // Straighten verticals and horizontals
143 virtual void Straighten(wxDC
& dc
);
146 inline void SetMaintainStraightLines(bool flag
) { m_maintainStraightLines
= flag
; }
147 inline bool GetMaintainStraightLines() const { return m_maintainStraightLines
; }
149 // Make handle control points
150 void MakeControlPoints();
151 void ResetControlPoints();
153 // Make a given number of control points
154 virtual void MakeLineControlPoints(int n
);
155 virtual wxNode
*InsertLineControlPoint(wxDC
* dc
);
156 virtual bool DeleteLineControlPoint();
157 virtual void Initialise();
158 inline wxList
*GetLineControlPoints() { return m_lineControlPoints
; }
160 // Override dragging behaviour - don't want to be able to drag lines!
161 void OnDragLeft(bool draw
, double x
, double y
, int keys
=0, int attachment
= 0);
162 void OnBeginDragLeft(double x
, double y
, int keys
=0, int attachment
= 0);
163 void OnEndDragLeft(double x
, double y
, int keys
=0, int attachment
= 0);
165 // Control points ('handles') redirect control to the actual shape, to make it easier
166 // to override sizing behaviour.
167 virtual void OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
=0, int attachment
= 0);
168 virtual void OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
=0, int attachment
= 0);
169 virtual void OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
=0, int attachment
= 0);
171 // Override select, to create/delete temporary label-moving objects
172 void Select(bool select
= TRUE
, wxDC
* dc
= NULL
);
174 // Set to spline (TRUE) or line (FALSE)
175 inline void SetSpline(bool spl
) { m_isSpline
= spl
; }
176 inline bool IsSpline() const { return m_isSpline
; }
179 void SetAttachments(int from_attach
, int to_attach
);
180 inline void SetAttachmentFrom(int attach
) { m_attachmentFrom
= attach
; }
181 inline void SetAttachmentTo(int attach
) { m_attachmentTo
= attach
; }
183 bool HitTest(double x
, double y
, int *attachment
, double *distance
);
186 // Prolog database stuff
187 virtual char *GetFunctor();
188 virtual void WritePrologAttributes(wxExpr
*clause
);
189 virtual void ReadPrologAttributes(wxExpr
*clause
);
192 virtual void FindNth(wxShape
*image
, int *nth
, int *no_arcs
, bool incoming
);
194 // Find which position we're talking about at this (x, y).
195 // Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END
196 int FindLinePosition(double x
, double y
);
198 // This is really to distinguish between lines and other images.
199 // For lines, want to pass drag to canvas, since lines tend to prevent
200 // dragging on a canvas (they get in the way.)
201 virtual bool Draggable() const { return FALSE
; }
203 // Does the copying for this object
204 void Copy(wxShape
& copy
);
207 wxArrowHead
*AddArrow(WXTYPE type
, int end
= ARROW_POSITION_END
,
208 double arrowSize
= 10.0, double xOffset
= 0.0, const wxString
& name
= "",
209 wxPseudoMetaFile
*mf
= NULL
, long arrowId
= -1);
211 // Add an arrowhead in the position indicated by the reference
212 // list of arrowheads, which contains all legal arrowheads for this
213 // line, in the correct order.
214 // E.g. reference list: a b c d e
215 // Current line list: a d
216 // Add c, then line list is: a c d
217 // If no legal arrowhead position, return FALSE.
218 // Assume reference list is for one end only, since it potentially defines
219 // the ordering for any one of the 3 positions. So we don't check
220 // the reference list for arrowhead position.
221 bool AddArrowOrdered(wxArrowHead
*arrow
, wxList
& referenceList
, int end
);
223 // Delete arrowhead(s)
224 void ClearArrowsAtPosition(int end
= -1);
225 bool ClearArrow(const wxString
& name
);
226 wxArrowHead
*FindArrowHead(int position
, const wxString
& name
);
227 wxArrowHead
*FindArrowHead(long arrowId
);
228 bool DeleteArrowHead(int position
, const wxString
& name
);
229 bool DeleteArrowHead(long arrowId
);
230 void DrawArrow(wxDC
& dc
, wxArrowHead
*arrow
, double xOffset
, bool proportionalOffset
);
231 inline void SetIgnoreOffsets(bool ignore
) { m_ignoreArrowOffsets
= ignore
; }
232 inline wxList
& GetArrows() const { return (wxList
&) m_arcArrows
; }
234 // Find horizontal width for drawing a line with
235 // arrows in minimum space. Assume arrows at
237 double FindMinimumWidth();
239 // Set alignment flags. ALIGNMENT NOT IMPLEMENTED.
240 void SetAlignmentOrientation(bool isEnd
, bool isHoriz
);
241 void SetAlignmentType(bool isEnd
, int alignType
);
242 bool GetAlignmentOrientation(bool isEnd
);
243 int GetAlignmentType(bool isEnd
);
245 // Find next control point in line after the start/end point
246 // (depending on whether the node object is at start or end)
247 wxRealPoint
*GetNextControlPoint(wxShape
*nodeObject
);
248 inline bool IsEnd(wxShape
*nodeObject
) const { return (m_to
== nodeObject
); }
251 bool m_erasing
; // flag to say whether we're erasing or drawing
252 // this line (really so metafiles can draw a
254 bool m_ignoreArrowOffsets
; // Don't always want to draw arrowhead offsets
255 // because they may not work on tool palettes (for example)
257 bool m_maintainStraightLines
;
260 // Temporary list of line segment orientations
261 // so we know what direction the line is supposed to be dog-legging
262 // in. The values are integer: 0 for vertical, 1 for horizontal.
263 wxList m_lineOrientations
;
265 // Temporary pointers for start, middle and end label editing objects
266 // (active only when the line is selected)
267 wxLabelShape
* m_labelObjects
[3];
269 // These define the segmented line - not to be confused with temporary control
270 // points which appear when object is selected (although in this case they'll
271 // probably be the same)
272 wxList
* m_lineControlPoints
;
274 double m_arrowSpacing
; // Separation between adjacent arrows
280 double m_actualTextWidth; // Space the text takes up
281 double m_actualTextHeight; // (depends on text content unlike nodes)
283 int m_attachmentTo
; // Attachment point at one end
284 int m_attachmentFrom
; // Attachment point at other end
287 int m_alignmentStart
;