1/*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions, and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions, and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * 3. The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32// DiagramWire.h (Cortex/DiagramView)
33//
34// * PURPOSE
35//   DiagramItem subclass serving as a graphical connection
36//   between two DiagramEndPoints
37//
38// * HISTORY
39//   c.lenz		25sep99		Begun
40//
41
42#ifndef __DiagramWire_H__
43#define __DiagramWire_H__
44
45#include "DiagramItem.h"
46
47#include <Region.h>
48#include <Window.h>
49
50#include "cortex_defs.h"
51__BEGIN_CORTEX_NAMESPACE
52
53class DiagramView;
54class DiagramEndPoint;
55
56class DiagramWire : public DiagramItem
57{
58	friend class DiagramView;
59
60public:					// *** ctor/dtor
61
62	// both endpoints are set connected by this constructor
63	// so be careful to only pass in valid pointers
64						DiagramWire(
65							DiagramEndPoint *fromWhich,
66							DiagramEndPoint *toWhich);
67
68	// special constructor used only in drag&drop sessions for
69	// temporary visual indication of the connection process
70	// the isStartPoint lets you specify if the given EndPoint
71	// is supposed to be treated as start or end point
72						DiagramWire(
73							DiagramEndPoint *fromWhich,
74							bool isStartPoint = true);
75
76	virtual				~DiagramWire();
77
78public:					// *** accessors
79
80	bool				isDragging() const
81						{ return m_temporary; }
82
83	// returns a pointer to the "start/source" endpoint
84	DiagramEndPoint	   *startPoint() const
85						{ return m_fromEndPoint; }
86
87	// returns the point from the m_fromEndPoints connectionPoint() method
88	BPoint				startConnectionPoint() const;
89
90	// returns a pointer the "end/target" endpoint
91	DiagramEndPoint	   *endPoint() const
92						{ return m_toEndPoint; }
93
94	// returns the point from the m_toEndPoints connectionPoint() method
95	BPoint				endConnectionPoint() const;
96
97public:					// *** hook functions
98
99	// is called from Draw() to do the actual drawing
100	virtual void		drawWire() = 0;
101
102	// is called by the connected diagramEndPoints whenever one is moved
103	// if the argument is NULL then both endpoints should be evaluated
104	virtual void		endPointMoved(
105							DiagramEndPoint *which = 0)
106						{ /* does nothing */ }
107
108public:					//  *** derived from DiagramItem
109
110	// returns the area in which the wire displays
111	virtual BRect		Frame() const
112						{ return BRect(startConnectionPoint(), endConnectionPoint()); }
113
114	// returns how close a given point is to the wire; the current
115	// implementation returns a wide array of values, those above
116	// approx. 0.5 are quite close to the wire
117	float				howCloseTo(
118							BPoint point) const;
119
120	// prepares the drawing stack and clipping region, then
121	// calls drawWire
122	void				Draw(
123							BRect updateRect);
124
125	// is called from the parent DiagramViews MouseDown() implementation
126	// if the Wire was hit; this version initiates selection and dragging
127	virtual void		MouseDown(
128							BPoint point,
129							uint32 buttons,
130							uint32 clicks);
131
132	// is called from the DiagramViews MouseMoved() when no message is being
133	// dragged, but the mouse has moved above the wire
134	virtual void		MouseOver(
135							BPoint point,
136							uint32 transit)
137						{ /* does nothing */ }
138
139
140	// is called from the DiagramViews MouseMoved() when a message is being
141	// dragged over the DiagramWire
142	virtual void		MessageDragged(
143							BPoint point,
144							uint32 transit,
145							const BMessage *message);
146
147	// is called from the DiagramViews MessageReceived() function when a
148	// message has been dropped on the DiagramWire
149	virtual void		MessageDropped(
150							BPoint point,
151							BMessage *message)
152						{ /* does nothing */ }
153
154private:				// *** data
155
156	// pointer to the "from" EndPoint as assigned in the ctor
157	DiagramEndPoint	   *m_fromEndPoint;
158
159	// pointer to the "to" EndPoint as assigned in the ctor
160	DiagramEndPoint	   *m_toEndPoint;
161
162	// indicates that this is a connection used in a drag&drop session
163	// and will be deleted after that
164	bool				m_temporary;
165
166	// contains a BPoint for "temporary connections"
167	BPoint				m_dragEndPoint;
168};
169
170__END_CORTEX_NAMESPACE
171#endif // __DiagramWire_H__
172