xref: /haiku/src/apps/cortex/MediaRoutingView/MediaJack.h (revision 3be9edf8da228afd9fec0390f408c964766122aa)
1 // MediaJack.h
2 // c.lenz 10oct99
3 //
4 // * PURPOSE
5 //	 DiagramEndPoint derived class implementing the drawing
6 //	 code and
7 //
8 // HISTORY
9 //
10 
11 #ifndef __MediaJack_H__
12 #define __MediaJack_H__
13 
14 #include "DiagramEndPoint.h"
15 
16 // Media Kit
17 #include <MediaDefs.h>
18 #include <MediaNode.h>
19 // Support Kit
20 #include <String.h>
21 
22 class BBitmap;
23 
24 #include "cortex_defs.h"
25 __BEGIN_CORTEX_NAMESPACE
26 
27 int compareTypeAndID(const void *lValue, const void *rValue);
28 
29 class MediaJack : public DiagramEndPoint
30 {
31 
32 public:					// *** jack types
33 
34 	enum jack_t
35 	{
36 		M_INPUT,
37 		M_OUTPUT
38 	};
39 
40 public:					// *** constants
41 
42 	// [e.moon 26oct99] moved definitions to MediaJack.cpp
43 	static float M_DEFAULT_WIDTH;
44 	static float M_DEFAULT_HEIGHT;
45 	static const float M_DEFAULT_GAP;
46 	static const int32 M_MAX_ABBR_LENGTH;
47 
48 public:					// *** ctor/dtor
49 
50 	// Constructor for input jacks
51 						MediaJack(
52 							media_input input);
53 
54 	// Constructor for output jacks
55 						MediaJack(
56 							media_output output);
57 
58 	virtual				~MediaJack();
59 
60 public:					// *** accessors
61 
62 	// returns the full name of the input/output
63 	BString				name() const
64 						{ return m_label; }
65 
66 	// return true if this is an input jack
67 	bool				isInput() const
68 						{ return (m_jackType == M_INPUT); }
69 
70 	// copies the media_input struct into input; returns
71 	// B_ERROR if this isn't an input jack
72 	status_t			getInput(
73 							media_input *input) const;
74 
75 	// return true if this is an output jack
76 	bool				isOutput() const
77 						{ return (m_jackType == M_OUTPUT); }
78 
79 	// copies the media_output struct into input; returns
80 	// B_ERROR if this isn't an input jack
81 	status_t			getOutput(
82 							media_output *output) const;
83 
84 public:					// *** derived from DiagramEndPoint/Item
85 
86 	// is called by the parent DiagramBox after adding endpoint
87 	virtual void		attachedToDiagram();
88 
89 	// is called by the parent DiagramBox just before the endpoint
90 	// will be removed
91 	virtual void		detachedFromDiagram();
92 
93 	// the actual drawing code
94 	virtual void		drawEndPoint();
95 
96 	// returns the coordinate at which a connected MediaWire is
97 	// supposed to start/end
98 	virtual BPoint		connectionPoint() const;
99 
100 	// hook called by the base class; just verifies if the jack
101 	// type isn't equal, i.e. not connecting an input to an input
102 	virtual bool		connectionRequested(
103 							DiagramEndPoint *which);
104 
105 	// displays the context menu for right-clicks
106 	virtual void		MouseDown(
107 							BPoint point,
108 							uint32 buttons,
109 							uint32 clicks);
110 
111 	// changes the mouse cursor and prepares a tooltip
112 	virtual void		MouseOver(
113 							BPoint point,
114 							uint32 transit);
115 
116 	// changes the mouse cursor
117 	virtual void		MessageDragged(
118 							BPoint point,
119 							uint32 transit,
120 							const BMessage *message);
121 
122 	// updates the offscreen bitmap
123 	virtual void		selected();
124 
125 	// updates the offscreen bitmap
126 	virtual void		deselected();
127 
128 	// updates the offscreen bitmap
129 	virtual void		connected();
130 
131 	// updates the offscreen bitmap
132 	virtual void		disconnected();
133 
134 public:					// *** operations
135 
136 	// updates the jacks bitmap
137 	void				layoutChanged(
138 							int32 layout);
139 
140 	// special function to be called by the parent MediaNodePanel
141 	// for simple positioning; this method only needs to know the
142 	// vertical offset of the jack and the left/right frame coords
143 	// of the panel
144 	void				setPosition(
145 							float verticalOffset,
146 							float leftBoundary,
147 							float rightBoundary,
148 							BRegion *updateRegion = 0);
149 
150 protected:					// *** operations
151 
152 	// display a popup-menu at given point
153 	void				showContextMenu(
154 							BPoint point);
155 
156 private:				// *** internal methods
157 
158 	// update the offscreen bitmap
159 	void				_updateBitmap();
160 
161 	// draw jack into the specified target view
162 	void				_drawInto(
163 							BView *target,
164 							BRect frame,
165 							int32 layout);
166 
167 	// make/update an abbreviation for the jacks name
168 	void				_updateAbbreviation();
169 
170 public:					// *** sorting methods
171 
172 	// used for sorting; will put input jacks before output jacks
173 	// and inside those sort by index
174 	friend int			compareTypeAndID(
175 							const void *lValue,
176 							const void *rValue);
177 
178 private:				// *** data
179 
180 	int32				m_jackType;
181 	BBitmap			   *m_bitmap;
182 	int32				m_index;
183 	media_node			m_node;
184 	media_source		m_source;
185 	media_destination	m_destination;
186 	media_format		m_format;
187 	BString				m_label;
188 	BString				m_abbreviation;
189 };
190 
191 __END_CORTEX_NAMESPACE
192 #endif /* __MediaJack_H__ */
193