xref: /haiku/src/apps/cortex/DiagramView/DiagramEndPoint.h (revision 19ae20e67e91fc09cc9fc5c0e60e21e24e7a53eb)
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 // DiagramItem.h (Cortex/DiagramView)
33 //
34 // * PURPOSE
35 //   DiagramItem subclass providing a basic implementation
36 //   of 'connectable' points inside a DiagramBox
37 //
38 // * HISTORY
39 //   c.lenz		25sep99		Begun
40 //
41 
42 #ifndef __DiagramEndPoint_H__
43 #define __DiagramEndPoint_H__
44 
45 #include <Looper.h>
46 #include <Region.h>
47 
48 #include "DiagramItem.h"
49 
50 #include "cortex_defs.h"
51 __BEGIN_CORTEX_NAMESPACE
52 
53 class DiagramWire;
54 
55 class DiagramEndPoint : public DiagramItem
56 {
57 
58 public:					// *** ctor/dtor
59 
60 						DiagramEndPoint(
61 							BRect frame);
62 
63 	virtual				~DiagramEndPoint();
64 
65 public:					// *** accessors
66 
wire()67 	DiagramWire		   *wire() const
68 						{ return m_wire; }
69 
70 public:					// *** hook functions
71 
72 	// is called from Draw() to do the actual drawing
73 	virtual void		drawEndPoint() = 0;
74 
75 	// should return the BPoint that a connected wire uses as
76 	// a drawing offset; this implementation returns the center
77 	// point of the EndPoint
78 	virtual BPoint		connectionPoint() const;
79 
80 	// is called from MessageDragged() and MessageDropped() to
81 	// let you verify that a connection is okay
82 	virtual bool		connectionRequested(
83 							DiagramEndPoint *fromWhich);
84 
85 	// is called whenever a connection has been made or a
86 	// temporary wire drag has been accepted
connected()87 	virtual void		connected()
88 						{ /* does nothing */ }
89 
90 	// is called whenever a connection has been broken or a
91 	// temporary wire drag has finished
disconnected()92 	virtual void		disconnected()
93 						{ /* does nothing */ }
94 
95 public:					// *** derived from DiagramItem
96 
97 	// returns the EndPoints frame rectangle
Frame()98 	BRect				Frame() const
99 						{ return m_frame; }
100 
101 	// prepares the drawing stack and clipping region, then
102 	// calls drawEndPoint
103 	void				Draw(
104 							BRect updateRect);
105 
106 	// is called from the parent DiagramBox's MouseDown()
107 	// implementation if the EndPoint was hit; this version
108 	// initiates selection and dragging (i.e. connecting)
109 	virtual void		MouseDown(
110 							BPoint point,
111 							uint32 buttons,
112 							uint32 clicks);
113 
114 	// is called from the parent DiagramBox's MouseOver()
115 	// implementation if the mouse is over the EndPoint
MouseOver(BPoint point,uint32 transit)116 	virtual void		MouseOver(
117 							BPoint point,
118 							uint32 transit)
119 						{ /* does nothing */ }
120 
121 	// is called from the parent DiagramBox's MessageDragged()
122 	// implementation of a message is being dragged of the
123 	// EndPoint; this implementation handles only wire drags
124 	// (i.e. M_WIRE_DRAGGED messages)
125 	virtual void		MessageDragged(
126 							BPoint point,
127 							uint32 transit,
128 							const BMessage *message);
129 
130 	// is called from the parent DiagramBox's MessageDropped()
131 	// implementation if the message was dropped on the EndPoint;
132 	// this version handles wire dropping (connecting)
133 	virtual void		MessageDropped(
134 							BPoint point,
135 							BMessage *message);
136 
137 	// moves the EndPoint by the specified amount and returns in
138 	// updateRegion the frames of connected wires if there are any
139 	// NOTE: no drawing/refreshing is done in this method, that's
140 	// up to the parent
141 	void				MoveBy(
142 							float x,
143 							float y,
144 							BRegion *updateRegion);
145 
146 	// resize the EndPoints frame rectangle without redraw
147 	virtual void		ResizeBy(
148 							float horizontal,
149 							float vertical);
150 
151 public:					// *** connection methods
152 
153 	// connect/disconnect and set the wire pointer accordingly
154 	void				connect(
155 							DiagramWire *wire);
156 	void				disconnect();
157 
158 	// returns true if the EndPoint is currently connected
isConnected()159 	bool				isConnected() const
160 						{ return m_connected; }
161 
162 	// returns true if the EndPoint is currently in a connection
163 	// process (i.e. it is either being dragged somewhere, or a
164 	// M_WIRE_DRAGGED message is being dragged over it
isConnecting()165 	bool				isConnecting() const
166 						{ return m_connecting; }
167 
168 private:				// *** data
169 
170 	// the endpoints' frame rectangle
171 	BRect				m_frame;
172 
173 	// pointer to the wire object this endpoint might be
174 	// connected to
175 	DiagramWire		   *m_wire;
176 
177 	// indicates if the endpoint is currently connected
178 	// to another endpoint
179 	bool				m_connected;
180 
181 	// indicates that a connection is currently being made
182 	// but has not been confirmed yet
183 	bool				m_connecting;
184 };
185 
186 __END_CORTEX_NAMESPACE
187 #endif // __DiagramEndPoint_H__
188