2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
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.
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.
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.
32 // DiagramEndPoint.cpp
34 #include "DiagramEndPoint.h"
35 #include "DiagramDefs.h"
36 #include "DiagramWire.h"
37 #include "DiagramView.h"
40 #include <Messenger.h>
41 __USE_CORTEX_NAMESPACE
44 #define D_METHOD(x) //PRINT (x)
45 #define D_MESSAGE(x) //PRINT (x)
46 #define D_MOUSE(x) //PRINT (x)
48 // -------------------------------------------------------- //
50 // -------------------------------------------------------- //
52 DiagramEndPoint::DiagramEndPoint(
54 : DiagramItem(DiagramItem::M_ENDPOINT
),
60 D_METHOD(("DiagramEndPoint::DiagramEndPoint()\n"));
64 DiagramEndPoint::~DiagramEndPoint()
66 D_METHOD(("DiagramEndPoint::~DiagramEndPoint()\n"));
69 // -------------------------------------------------------- //
71 // -------------------------------------------------------- //
73 BPoint
DiagramEndPoint::connectionPoint() const
75 D_METHOD(("DiagramEndPoint::connectionPoint()\n"));
76 return BPoint(Frame().left
+ Frame().Height() / 2.0, Frame().top
+ Frame().Width() / 2.0);
79 bool DiagramEndPoint::connectionRequested(
80 DiagramEndPoint
*fromWhich
)
82 D_METHOD(("DiagramEndPoint::connectionRequested()\n"));
90 // -------------------------------------------------------- //
91 // *** derived from DiagramItem
92 // -------------------------------------------------------- //
94 void DiagramEndPoint::Draw(
97 D_METHOD(("DiagramEndPoint::Draw()\n"));
103 region
.Include(Frame() & updateRect
);
104 view()->ConstrainClippingRegion(®ion
);
111 void DiagramEndPoint::MouseDown(
116 D_MOUSE(("DiagramEndPoint::MouseDown()\n"));
121 BMessage
selectMsg(M_SELECTION_CHANGED
);
122 if (modifiers() & B_SHIFT_KEY
)
124 selectMsg
.AddBool("replace", false);
128 selectMsg
.AddBool("replace", true);
130 selectMsg
.AddPointer("item", reinterpret_cast<void *>(this));
131 DiagramView
* v
= view();
132 BMessenger(v
).SendMessage(&selectMsg
);
134 if (isDraggable() && (buttons
== B_PRIMARY_MOUSE_BUTTON
))
136 BMessage
dragMsg(M_WIRE_DRAGGED
);
137 dragMsg
.AddPointer("from", static_cast<void *>(this));
138 view()->DragMessage(&dragMsg
, BRect(0.0, 0.0, -1.0, -1.0), view());
139 view()->MessageDragged(point
, B_INSIDE_VIEW
, &dragMsg
);
144 void DiagramEndPoint::MessageDragged(
147 const BMessage
*message
)
149 D_MOUSE(("DiagramEndPoint::MessageDragged()\n"));
150 switch (message
->what
)
154 D_MESSAGE(("DiagramEndPoint::MessageDragged(M_WIRE_DRAGGED)\n"));
159 //PRINT((" -> transit: B_INSIDE_VIEW\n"));
160 // this is a WORK-AROUND caused by the unreliability
161 // of BViews DragMessage() routine !!
166 else if (isConnected())
168 view()->trackWire(point
);
170 /* this should be enough in theory:
173 view()->trackWire(point);
179 //PRINT((" -> transit: B_ENTERED_VIEW\n"));
180 DiagramEndPoint
*endPoint
;
181 if ((message
->FindPointer("from", reinterpret_cast<void **>(&endPoint
)) == B_OK
)
182 && (endPoint
!= this))
184 if (connectionRequested(endPoint
))
186 view()->trackWire(connectionPoint());
195 view()->trackWire(point
);
198 m_connecting
= false;
207 //PRINT((" -> transit: B_EXITED_VIEW\n"));
210 m_connecting
= false;
220 DiagramItem::MessageDragged(point
, transit
, message
);
225 void DiagramEndPoint::MessageDropped(
229 D_MESSAGE(("DiagramEndPoint::MessageDropped()\n"));
230 switch (message
->what
)
234 D_MESSAGE(("DiagramEndPoint::MessageDropped(M_WIRE_DRAGGED)\n"));
235 DiagramEndPoint
*endPoint
;
236 if ((message
->FindPointer("from", reinterpret_cast<void **>(&endPoint
)) == B_OK
)
237 && (endPoint
!= this))
239 bool success
= connectionRequested(endPoint
);
240 BMessage
dropMsg(M_WIRE_DROPPED
);
241 dropMsg
.AddPointer("from", reinterpret_cast<void *>(endPoint
));
242 dropMsg
.AddPointer("to", reinterpret_cast<void *>(this));
243 dropMsg
.AddBool("success", success
);
244 DiagramView
* v
= view();
245 BMessenger(v
).SendMessage(&dropMsg
);
248 m_connecting
= false;
256 DiagramItem::MessageDropped(point
, message
);
261 // -------------------------------------------------------- //
262 // *** frame related operations
263 // -------------------------------------------------------- //
265 void DiagramEndPoint::MoveBy(
268 BRegion
*updateRegion
)
270 D_METHOD(("DiagramEndPoint::MoveBy()\n"));
271 if (isConnected() && m_wire
&& updateRegion
)
273 updateRegion
->Include(m_wire
->Frame());
274 m_frame
.OffsetBy(x
, y
);
275 m_wire
->endPointMoved(this);
276 updateRegion
->Include(m_wire
->Frame());
280 m_frame
.OffsetBy(x
, y
);
283 m_wire
->endPointMoved(this);
288 void DiagramEndPoint::ResizeBy(
292 D_METHOD(("DiagramEndPoint::ResizeBy()\n"));
293 m_frame
.right
+= horizontal
;
294 m_frame
.bottom
+= vertical
;
297 // -------------------------------------------------------- //
298 // *** connection methods
299 // -------------------------------------------------------- //
301 void DiagramEndPoint::connect(
304 D_METHOD(("DiagramEndPoint::connect()\n"));
305 if (!m_connected
&& wire
)
309 makeDraggable(false);
314 void DiagramEndPoint::disconnect()
316 D_METHOD(("DiagramEndPoint::disconnect()\n"));
326 // END -- DiagramEndPoint.cpp --