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