]> git.saurik.com Git - wxWidgets.git/blame_incremental - contrib/include/wx/ogl/lines.h
added .chm support for Unix (Markus Sinner)
[wxWidgets.git] / contrib / include / wx / ogl / lines.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: lines.h
3// Purpose: wxLineShape
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_LINES_H_
13#define _OGL_LINES_H_
14
15#if defined(__GNUG__) && !defined(__APPLE__)
16#pragma interface "lines.h"
17#endif
18
19
20class WXDLLIMPEXP_OGL wxLabelShape;
21class WXDLLIMPEXP_OGL wxPseudoMetaFile;
22class WXDLLIMPEXP_OGL wxLineControlPoint;
23/*
24 * Arcs with multiple arrowheads
25 *
26 */
27
28// Types of arrowhead
29// (i) Built-in
30#define ARROW_HOLLOW_CIRCLE 1
31#define ARROW_FILLED_CIRCLE 2
32#define ARROW_ARROW 3
33#define ARROW_SINGLE_OBLIQUE 4
34#define ARROW_DOUBLE_OBLIQUE 5
35// (ii) Custom
36#define ARROW_METAFILE 20
37
38// Position of arrow on line
39#define ARROW_POSITION_START 0
40#define ARROW_POSITION_END 1
41#define ARROW_POSITION_MIDDLE 2
42
43// Line alignment flags
44// Vertical by default
45#define LINE_ALIGNMENT_HORIZ 1
46#define LINE_ALIGNMENT_VERT 0
47#define LINE_ALIGNMENT_TO_NEXT_HANDLE 2
48#define LINE_ALIGNMENT_NONE 0
49
50class WXDLLIMPEXP_OGL wxArrowHead: public wxObject
51{
52 DECLARE_DYNAMIC_CLASS(wxArrowHead)
53
54 public:
55 wxArrowHead(WXTYPE type = 0, int end = 0, double size = 0.0, double dist = 0.0, const wxString& name = wxEmptyString, wxPseudoMetaFile *mf = NULL,
56 long arrowId = -1);
57 ~wxArrowHead();
58 wxArrowHead(wxArrowHead& toCopy);
59
60 inline WXTYPE _GetType() const { return m_arrowType; }
61 inline int GetPosition() const { return m_arrowEnd; }
62 inline void SetPosition(int pos) { m_arrowEnd = pos; }
63 inline double GetXOffset() const { return m_xOffset; }
64 inline double GetYOffset() const { return m_yOffset; }
65 inline double GetSpacing() const { return m_spacing; }
66 inline double GetSize() const { return m_arrowSize; }
67 inline wxString GetName() const { return m_arrowName; }
68 inline void SetXOffset(double x) { m_xOffset = x; }
69 inline void SetYOffset(double y) { m_yOffset = y; }
70 inline wxPseudoMetaFile *GetMetaFile() const { return m_metaFile; }
71 inline long GetId() const { return m_id; }
72 inline int GetArrowEnd() const { return m_arrowEnd; }
73 inline double GetArrowSize() const { return m_arrowSize; }
74 void SetSize(double size);
75 inline void SetSpacing(double sp) { m_spacing = sp; }
76
77 protected:
78 WXTYPE m_arrowType;
79 int m_arrowEnd; // Position on line
80 double m_xOffset; // Distance from arc start or end, w.r.t. point on arrowhead
81 // nearest start or end. If zero, use default spacing.
82 double m_yOffset; // vertical offset (w.r.t. a horizontal line). Normally zero.
83 double m_spacing; // Spacing from the last arrowhead
84 double m_arrowSize; // Length of arrowhead
85 wxString m_arrowName; // Name of arrow
86 bool m_saveToFile; // TRUE if we want to save custom arrowheads to file.
87 wxPseudoMetaFile* m_metaFile; // Pseudo metafile if this is a custom arrowhead
88 long m_id; // identifier
89};
90
91// Line object
92class WXDLLIMPEXP_OGL wxLabelShape;
93class WXDLLIMPEXP_OGL wxLineShape: public wxShape
94{
95 DECLARE_DYNAMIC_CLASS(wxLineShape)
96
97 public:
98 wxLineShape();
99 ~wxLineShape();
100
101 // Called when a connected object has moved, to move the link to
102 // correct position
103 // moveControlPoints must be disabled when a control point is being
104 // dragged.
105 void OnMoveLink(wxDC& dc, bool moveControlPoints = TRUE);
106 bool OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
107 void OnDraw(wxDC& dc);
108 void OnDrawContents(wxDC& dc);
109 void OnDrawControlPoints(wxDC& dc);
110 void OnEraseControlPoints(wxDC& dc);
111 void OnErase(wxDC& dc);
112 virtual bool OnMoveControlPoint(int WXUNUSED(which), double WXUNUSED(x), double WXUNUSED(y)) { return FALSE; }
113 virtual bool OnMoveMiddleControlPoint(wxDC& dc, wxLineControlPoint* lpt, const wxRealPoint& pt);
114 virtual bool OnLabelMovePre(wxDC& dc, wxLabelShape* labelShape, double x, double y, double old_x, double old_y, bool display);
115 void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
116 void GetBoundingBoxMin(double *w, double *h);
117 void FormatText(wxDC& dc, const wxString& s, int regionId = 0);
118 virtual void SetEnds(double x1, double y1, double x2, double y2);
119 virtual void GetEnds(double *x1, double *y1, double *x2, double *y2);
120 inline virtual wxShape *GetFrom() { return m_from; }
121 inline virtual wxShape *GetTo() { return m_to; }
122 inline virtual int GetAttachmentFrom() { return m_attachmentFrom; }
123 inline virtual int GetAttachmentTo() { return m_attachmentTo; }
124
125 virtual void SetFrom(wxShape *object);
126 virtual void SetTo(wxShape *object);
127 virtual void DrawArrows(wxDC& dc);
128
129 // Finds the x, y points at the two ends of the line.
130 // This function can be used by e.g. line-routing routines to
131 // get the actual points on the two node images where the lines will be drawn
132 // to/from.
133 void FindLineEndPoints(double *fromX, double *fromY, double *toX, double *toY);
134
135 // Format one region at this position
136 void DrawRegion(wxDC& dc, wxShapeRegion *region, double x, double y);
137
138 // Erase one region at this position
139 void EraseRegion(wxDC& dc, wxShapeRegion *region, double x, double y);
140
141 // Get the reference point for a label. Region x and y
142 // are offsets from this.
143 // position is 0 (middle), 1 (start), 2 (end)
144 void GetLabelPosition(int position, double *x, double *y);
145
146 // Can override this to create a different class of label shape
147 virtual wxLabelShape* OnCreateLabelShape(wxLineShape *parent = NULL, wxShapeRegion *region = NULL, double w = 0.0, double h = 0.0);
148
149 // Straighten verticals and horizontals
150 virtual void Straighten(wxDC* dc = NULL);
151
152 // Not implemented
153 inline void SetMaintainStraightLines(bool flag) { m_maintainStraightLines = flag; }
154 inline bool GetMaintainStraightLines() const { return m_maintainStraightLines; }
155
156 // Make handle control points
157 void MakeControlPoints();
158 void ResetControlPoints();
159
160 // Make a given number of control points
161 virtual void MakeLineControlPoints(int n);
162 virtual wxNode *InsertLineControlPoint(wxDC* dc);
163 virtual bool DeleteLineControlPoint();
164 virtual void Initialise();
165 inline wxList *GetLineControlPoints() { return m_lineControlPoints; }
166
167 // Override dragging behaviour - don't want to be able to drag lines!
168 void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0);
169 void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
170 void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
171
172 // Control points ('handles') redirect control to the actual shape, to make it easier
173 // to override sizing behaviour.
174 virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0);
175 virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
176 virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
177
178 // Override select, to create/delete temporary label-moving objects
179 void Select(bool select = TRUE, wxDC* dc = NULL);
180
181 // Set to spline (TRUE) or line (FALSE)
182 inline void SetSpline(bool spl) { m_isSpline = spl; }
183 inline bool IsSpline() const { return m_isSpline; }
184
185 void Unlink();
186 void SetAttachments(int from_attach, int to_attach);
187 inline void SetAttachmentFrom(int attach) { m_attachmentFrom = attach; }
188 inline void SetAttachmentTo(int attach) { m_attachmentTo = attach; }
189
190 bool HitTest(double x, double y, int *attachment, double *distance);
191
192#if wxUSE_PROLOGIO
193 // I/O
194 virtual void WriteAttributes(wxExpr *clause);
195 virtual void ReadAttributes(wxExpr *clause);
196#endif
197
198 virtual void FindNth(wxShape *image, int *nth, int *no_arcs, bool incoming);
199
200 // Find which position we're talking about at this (x, y).
201 // Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END
202 int FindLinePosition(double x, double y);
203
204 // This is really to distinguish between lines and other images.
205 // For lines, want to pass drag to canvas, since lines tend to prevent
206 // dragging on a canvas (they get in the way.)
207 virtual bool Draggable() const { return FALSE; }
208
209 // Does the copying for this object
210 void Copy(wxShape& copy);
211
212 // Add an arrowhead.
213 wxArrowHead *AddArrow(WXTYPE type, int end = ARROW_POSITION_END,
214 double arrowSize = 10.0, double xOffset = 0.0,
215 const wxString& name = wxEmptyString,
216 wxPseudoMetaFile *mf = NULL, long arrowId = -1);
217
218 // Add an arrowhead in the position indicated by the reference
219 // list of arrowheads, which contains all legal arrowheads for this
220 // line, in the correct order.
221 // E.g. reference list: a b c d e
222 // Current line list: a d
223 // Add c, then line list is: a c d
224 // If no legal arrowhead position, return FALSE.
225 // Assume reference list is for one end only, since it potentially defines
226 // the ordering for any one of the 3 positions. So we don't check
227 // the reference list for arrowhead position.
228 bool AddArrowOrdered(wxArrowHead *arrow, wxList& referenceList, int end);
229
230 // Delete arrowhead(s)
231 void ClearArrowsAtPosition(int end = -1);
232 bool ClearArrow(const wxString& name);
233 wxArrowHead *FindArrowHead(int position, const wxString& name);
234 wxArrowHead *FindArrowHead(long arrowId);
235 bool DeleteArrowHead(int position, const wxString& name);
236 bool DeleteArrowHead(long arrowId);
237 void DrawArrow(wxDC& dc, wxArrowHead *arrow, double xOffset, bool proportionalOffset);
238 inline void SetIgnoreOffsets(bool ignore) { m_ignoreArrowOffsets = ignore; }
239 inline wxList& GetArrows() const { return (wxList&) m_arcArrows; }
240
241 // Find horizontal width for drawing a line with
242 // arrows in minimum space. Assume arrows at
243 // END only
244 double FindMinimumWidth();
245
246 // Set alignment flags. ALIGNMENT NOT IMPLEMENTED.
247 void SetAlignmentOrientation(bool isEnd, bool isHoriz);
248 void SetAlignmentType(bool isEnd, int alignType);
249 bool GetAlignmentOrientation(bool isEnd);
250 int GetAlignmentType(bool isEnd);
251
252 // Find next control point in line after the start/end point
253 // (depending on whether the node object is at start or end)
254 wxRealPoint *GetNextControlPoint(wxShape *nodeObject);
255 inline bool IsEnd(wxShape *nodeObject) const { return (m_to == nodeObject); }
256
257private:
258 bool m_erasing; // flag to say whether we're erasing or drawing
259 // this line (really so metafiles can draw a
260 // blank rectangle)
261 bool m_ignoreArrowOffsets; // Don't always want to draw arrowhead offsets
262 // because they may not work on tool palettes (for example)
263 bool m_isSpline;
264 bool m_maintainStraightLines;
265
266protected:
267 // Temporary list of line segment orientations
268 // so we know what direction the line is supposed to be dog-legging
269 // in. The values are integer: 0 for vertical, 1 for horizontal.
270 wxList m_lineOrientations;
271
272 // Temporary pointers for start, middle and end label editing objects
273 // (active only when the line is selected)
274 wxLabelShape* m_labelObjects[3];
275
276 // These define the segmented line - not to be confused with temporary control
277 // points which appear when object is selected (although in this case they'll
278 // probably be the same)
279 wxList* m_lineControlPoints;
280
281 double m_arrowSpacing; // Separation between adjacent arrows
282
283 wxShape* m_to;
284 wxShape* m_from;
285
286 int m_attachmentTo; // Attachment point at one end
287 int m_attachmentFrom; // Attachment point at other end
288
289 // Alignment flags
290 int m_alignmentStart;
291 int m_alignmentEnd;
292
293 wxList m_arcArrows;
294
295};
296
297#endif
298 // _OGL_LINES_H_