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