BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / cortex / DiagramView / DiagramView.h
blob0e9ac90c62a318b5bac2d3b4887bda1cd8b3f665
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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)
34 // * PURPOSE
35 // BView and DiagramItemGroup derived class providing the
36 // one and only drawing context all child DiagramItems will
37 // use.
39 // * HISTORY
40 // c.lenz 25sep99 Begun
43 #ifndef __DiagramView_H__
44 #define __DiagramView_H__
46 #include "DiagramItemGroup.h"
48 #include <Region.h>
49 #include <View.h>
51 //class BBitmap;
53 #include "cortex_defs.h"
54 __BEGIN_CORTEX_NAMESPACE
56 //class DiagramBox;
57 class DiagramWire;
58 class DiagramEndPoint;
60 class DiagramView : public BView,
61 public DiagramItemGroup
64 public: // *** ctor/dtor
66 DiagramView(
67 BRect frame,
68 const char *name,
69 bool multiSelection,
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
91 // derived class
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(
104 BPoint point,
105 uint32 buttons,
106 uint32 clicks)
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(
112 BPoint point,
113 uint32 transit)
114 { /* does nothing */ }
116 // hook called from MouseMoved() if a message is being dragged
117 // over the background
118 virtual void MessageDragged(
119 BPoint point,
120 uint32 transit,
121 const BMessage *message);
123 // hook called from MessageReceived() if a message has been
124 // dropped over the background
125 virtual void MessageDropped(
126 BPoint point,
127 BMessage *message);
129 public: // derived from BView
131 // initial scrollbar update [e.moon 16nov99]
132 virtual void AttachedToWindow();
134 // draw the background and all items
135 virtual void Draw(
136 BRect updateRect);
138 // updates the scrollbars
139 virtual void FrameResized(
140 float width,
141 float height);
143 // return data rect [c.lenz 1mar2000]
144 virtual void GetPreferredSize(
145 float *width,
146 float *height);
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(
151 BMessage *message);
153 // handles the arrow keys for moving DiagramBoxes
154 virtual void KeyDown(
155 const char *bytes,
156 int32 numBytes);
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(
162 BPoint point);
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(
168 BPoint point,
169 uint32 transit,
170 const BMessage *message);
172 // ends rect-tracking and wire-tracking
173 virtual void MouseUp(
174 BPoint point);
176 public: // *** derived from DiagramItemGroup
178 // extends the DiagramItemGroup implementation by setting
179 // the items owner and calling the attachedToDiagram() hook
180 // on it
181 virtual bool AddItem(
182 DiagramItem *item);
184 // extends the DiagramItemGroup implementation by calling
185 // the detachedToDiagram() hook on the item
186 virtual bool RemoveItem(
187 DiagramItem *item);
189 public: // *** operations
191 // update the temporary wire to follow the mouse cursor
192 void trackWire(
193 BPoint point);
195 bool isWireTracking() const
196 { return m_draggedWire; }
198 protected: // *** internal operations
200 // do the actual background drawing
201 void drawBackground(
202 BRect updateRect);
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(
210 rgb_color color);
212 // set the background bitmap; does not refresh the display
213 void setBackgroundBitmap(
214 BBitmap *bitmap);
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(
234 BPoint origin);
236 // takes care of actually selecting/deselecting boxes when
237 // they intersect with the tracked rect
238 void _trackRect(
239 BPoint origin,
240 BPoint current);
242 // updates the scrollbars (if there are any) to represent
243 // the current data-rect
244 void _updateScrollBars();
246 private: // *** data
248 // the button pressed at the last mouse event
249 int32 m_lastButton;
251 // the number of clicks with the last button
252 int32 m_clickCount;
254 // the point last clicked in this view
255 BPoint m_lastClickPoint;
257 // the button currently pressed (reset to 0 on mouse-up)
258 // [e.moon 16nov99]
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
266 // tracking
267 DiagramWire *m_draggedWire;
269 // contains the rects of all DiagramBoxes in this view
270 BRegion m_boxRegion;
272 // contains the rect of the view actually containing something
273 // (i.e. DiagramBoxes) and all free space left/above of that
274 BRect m_dataRect;
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__