1 // DiagramWire.h (Cortex/DiagramView) 2 // 3 // * PURPOSE 4 // DiagramItem subclass serving as a graphical connection 5 // between two DiagramEndPoints 6 // 7 // * HISTORY 8 // c.lenz 25sep99 Begun 9 // 10 11 #ifndef __DiagramWire_H__ 12 #define __DiagramWire_H__ 13 14 #include "DiagramItem.h" 15 16 #include <Region.h> 17 #include <Window.h> 18 19 #include "cortex_defs.h" 20 __BEGIN_CORTEX_NAMESPACE 21 22 class DiagramView; 23 class DiagramEndPoint; 24 25 class DiagramWire : public DiagramItem 26 { 27 friend class DiagramView; 28 29 public: // *** ctor/dtor 30 31 // both endpoints are set connected by this constructor 32 // so be careful to only pass in valid pointers 33 DiagramWire( 34 DiagramEndPoint *fromWhich, 35 DiagramEndPoint *toWhich); 36 37 // special constructor used only in drag&drop sessions for 38 // temporary visual indication of the connection process 39 // the isStartPoint lets you specify if the given EndPoint 40 // is supposed to be treated as start or end point 41 DiagramWire( 42 DiagramEndPoint *fromWhich, 43 bool isStartPoint = true); 44 45 virtual ~DiagramWire(); 46 47 public: // *** accessors 48 49 bool isDragging() const 50 { return m_temporary; } 51 52 // returns a pointer to the "start/source" endpoint 53 DiagramEndPoint *startPoint() const 54 { return m_fromEndPoint; } 55 56 // returns the point from the m_fromEndPoints connectionPoint() method 57 BPoint startConnectionPoint() const; 58 59 // returns a pointer the "end/target" endpoint 60 DiagramEndPoint *endPoint() const 61 { return m_toEndPoint; } 62 63 // returns the point from the m_toEndPoints connectionPoint() method 64 BPoint endConnectionPoint() const; 65 66 public: // *** hook functions 67 68 // is called from Draw() to do the actual drawing 69 virtual void drawWire() = 0; 70 71 // is called by the connected diagramEndPoints whenever one is moved 72 // if the argument is NULL then both endpoints should be evaluated 73 virtual void endPointMoved( 74 DiagramEndPoint *which = 0) 75 { /* does nothing */ } 76 77 public: // *** derived from DiagramItem 78 79 // returns the area in which the wire displays 80 virtual BRect Frame() const 81 { return BRect(startConnectionPoint(), endConnectionPoint()); } 82 83 // returns how close a given point is to the wire; the current 84 // implementation returns a wide array of values, those above 85 // approx. 0.5 are quite close to the wire 86 float howCloseTo( 87 BPoint point) const; 88 89 // prepares the drawing stack and clipping region, then 90 // calls drawWire 91 void Draw( 92 BRect updateRect); 93 94 // is called from the parent DiagramViews MouseDown() implementation 95 // if the Wire was hit; this version initiates selection and dragging 96 virtual void MouseDown( 97 BPoint point, 98 uint32 buttons, 99 uint32 clicks); 100 101 // is called from the DiagramViews MouseMoved() when no message is being 102 // dragged, but the mouse has moved above the wire 103 virtual void MouseOver( 104 BPoint point, 105 uint32 transit) 106 { /* does nothing */ } 107 108 109 // is called from the DiagramViews MouseMoved() when a message is being 110 // dragged over the DiagramWire 111 virtual void MessageDragged( 112 BPoint point, 113 uint32 transit, 114 const BMessage *message); 115 116 // is called from the DiagramViews MessageReceived() function when a 117 // message has been dropped on the DiagramWire 118 virtual void MessageDropped( 119 BPoint point, 120 BMessage *message) 121 { /* does nothing */ } 122 123 private: // *** data 124 125 // pointer to the "from" EndPoint as assigned in the ctor 126 DiagramEndPoint *m_fromEndPoint; 127 128 // pointer to the "to" EndPoint as assigned in the ctor 129 DiagramEndPoint *m_toEndPoint; 130 131 // indicates that this is a connection used in a drag&drop session 132 // and will be deleted after that 133 bool m_temporary; 134 135 // contains a BPoint for "temporary connections" 136 BPoint m_dragEndPoint; 137 }; 138 139 __END_CORTEX_NAMESPACE 140 #endif // __DiagramWire_H__ 141