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 // DiagramView.h (Cortex/DiagramView)
35 // BView and DiagramItemGroup derived class providing the
36 // one and only drawing context all child DiagramItems will
40 // c.lenz 25sep99 Begun
43 #ifndef __DiagramView_H__
44 #define __DiagramView_H__
46 #include "DiagramItemGroup.h"
53 #include "cortex_defs.h"
54 __BEGIN_CORTEX_NAMESPACE
58 class DiagramEndPoint
;
60 class DiagramView
: public BView
,
61 public DiagramItemGroup
64 public: // *** ctor/dtor
70 uint32 resizingMode
= B_FOLLOW_LEFT
| B_FOLLOW_TOP
,
71 uint32 flags
= B_WILL_DRAW
);
73 virtual ~DiagramView();
75 public: // *** hook functions
77 // is called from MessageReceived() if a wire has been dropped
78 // on the background or on an incompatible endpoint
79 virtual void connectionAborted(
80 DiagramEndPoint
*fromWhich
)
81 { /* does nothing */ }
83 // is called from MessageReceived() if an endpoint has accepted
84 // a wire-drop (i.e. connection)
85 virtual void connectionEstablished(
86 DiagramEndPoint
*fromWhich
,
87 DiagramEndPoint
*toWhich
)
88 { /* does nothing */ }
90 // must be implemented to return an instance of the DiagramWire
92 virtual DiagramWire
*createWire(
93 DiagramEndPoint
*fromWhich
,
94 DiagramEndPoint
*woWhich
) = 0;
96 // must be implemented to return an instance of the DiagramWire
97 // derived class; this version is for temporary wires used in
98 // drag & drop connecting
99 virtual DiagramWire
*createWire(
100 DiagramEndPoint
*fromWhich
) = 0;
102 // hook called from BackgroundMouseDown() if the background was hit
103 virtual void BackgroundMouseDown(
107 { /* does nothing */ }
109 // hook called from MouseMoved() if the mouse is floating over
110 // the background (i.e. with no message attached)
111 virtual void MouseOver(
114 { /* does nothing */ }
116 // hook called from MouseMoved() if a message is being dragged
117 // over the background
118 virtual void MessageDragged(
121 const BMessage
*message
);
123 // hook called from MessageReceived() if a message has been
124 // dropped over the background
125 virtual void MessageDropped(
129 public: // derived from BView
131 // initial scrollbar update [e.moon 16nov99]
132 virtual void AttachedToWindow();
134 // draw the background and all items
138 // updates the scrollbars
139 virtual void FrameResized(
143 // return data rect [c.lenz 1mar2000]
144 virtual void GetPreferredSize(
148 // handles the messages M_SELECTION_CHANGED and M_WIRE_DROPPED
149 // and passes a dropped message on to the item it was dropped on
150 virtual void MessageReceived(
153 // handles the arrow keys for moving DiagramBoxes
154 virtual void KeyDown(
158 // if an item is located at the click point, this function calls
159 // that items MouseDown() method; else a deselectAll() command is
160 // made and rect-tracking is initiated
161 virtual void MouseDown(
164 // if an item is located under the given point, this function
165 // calls that items MessageDragged() hook if a message is being
166 // dragged, and MouseOver() if not
167 virtual void MouseMoved(
170 const BMessage
*message
);
172 // ends rect-tracking and wire-tracking
173 virtual void MouseUp(
176 public: // *** derived from DiagramItemGroup
178 // extends the DiagramItemGroup implementation by setting
179 // the items owner and calling the attachedToDiagram() hook
181 virtual bool AddItem(
184 // extends the DiagramItemGroup implementation by calling
185 // the detachedToDiagram() hook on the item
186 virtual bool RemoveItem(
189 public: // *** operations
191 // update the temporary wire to follow the mouse cursor
195 bool isWireTracking() const
196 { return m_draggedWire
; }
198 protected: // *** internal operations
200 // do the actual background drawing
204 // returns the current background color
205 rgb_color
backgroundColor() const
206 { return m_backgroundColor
; }
208 // set the background color; does not refresh the display
209 void setBackgroundColor(
212 // set the background bitmap; does not refresh the display
213 void setBackgroundBitmap(
216 // updates the region containing the rects of all boxes in
217 // the view (and thereby the "data-rect") and then adapts
218 // the scrollbars if necessary
219 void updateDataRect();
221 private: // *** internal operations
223 // setup a temporary wire for "live" dragging and attaches
224 // a message to the mouse
225 void _beginWireTracking(
226 DiagramEndPoint
*fromEndPoint
);
228 // delete the temporary dragged wire and invalidate display
229 void _endWireTracking();
231 // setups rect-tracking to additionally drag a message for
232 // easier identification in MouseMoved()
233 void _beginRectTracking(
236 // takes care of actually selecting/deselecting boxes when
237 // they intersect with the tracked rect
242 // updates the scrollbars (if there are any) to represent
243 // the current data-rect
244 void _updateScrollBars();
248 // the button pressed at the last mouse event
251 // the number of clicks with the last button
254 // the point last clicked in this view
255 BPoint m_lastClickPoint
;
257 // the button currently pressed (reset to 0 on mouse-up)
259 int32 m_pressedButton
;
261 // last mouse position in screen coordinates [e.moon 16nov99]
262 // only valid while m_pressedButton != 0
263 BPoint m_lastDragPoint
;
265 // a pointer to the temporary wire used for wire
267 DiagramWire
*m_draggedWire
;
269 // contains the rects of all DiagramBoxes in this view
272 // contains the rect of the view actually containing something
273 // (i.e. DiagramBoxes) and all free space left/above of that
276 // true if a bitmap is used for the background; false
277 // if a color is used
278 bool m_useBackgroundBitmap
;
280 // the background color of the view
281 rgb_color m_backgroundColor
;
283 // the background bitmap of the view
284 BBitmap
*m_backgroundBitmap
;
287 __END_CORTEX_NAMESPACE
288 #endif // __DiagramView_H__