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// MediaRoutingView.h
33// c.lenz 9oct99
34//
35// PURPOSE
36//   Provide a simple interface for the BeOS/Genki media system.
37//   Displays all the currently running ('live') media nodes,
38//   and represents the connections between them visually.
39//
40// NOTES
41//
42// *** 9oct99: replaced grid-based version
43//
44// HISTORY
45//   e.moon 6may99: first stab
46//   c.lenz 6oct99: starting change to DiagramView impl
47
48#ifndef __MediaRoutingView__H__
49#define __MediaRoutingView__H__
50
51// DiagramView
52#include "DiagramView.h"
53
54// Media Kit
55#include "MediaDefs.h"
56
57#include <Entry.h>
58#include <List.h>
59#include <Message.h>
60
61#include "IStateArchivable.h"
62
63#include "cortex_defs.h"
64__BEGIN_CORTEX_NAMESPACE
65
66// MediaRoutingView
67class MediaNodePanel;
68class MediaWire;
69// NodeManager
70class RouteAppNodeManager;
71class NodeGroup;
72class NodeRef;
73class Connection;
74// RouteApp
75class NodeSetIOContext;
76
77class MediaRoutingView :
78	public		DiagramView,
79	public		IStateArchivable {
80	typedef		DiagramView _inherited;
81
82public:					// *** constants
83
84	// [e.moon 26oct99] moved definitions to MediaRoutingView.cpp
85	static float	M_CLEANUP_H_GAP;
86	static float	M_CLEANUP_V_GAP;
87	static float	M_CLEANUP_H_MARGIN;
88	static float	M_CLEANUP_V_MARGIN;
89
90	// [e.moon 7dec99] enum now a named type
91	enum layout_t
92	{
93		M_ICON_VIEW = 1,
94		M_MINI_ICON_VIEW
95	};
96
97public:					//  messages
98
99	enum message_t {
100		// INBOUND
101		// "layout"		int32:			M_ICON_VIEW / M_MINI_ICON_VIEW
102		M_LAYOUT_CHANGED,
103
104		// INBOUND
105		M_CLEANUP_REQUESTED,
106
107		// INBOUND
108		// release/delete node
109		// "nodeID"		[u]int32:		node to release
110		M_RELEASE_NODE,
111
112		// INBOUND
113		M_SELECT_ALL,
114
115		// INBOUND
116		M_DELETE_SELECTION,
117
118		// OUTBOUND
119		// describes a selected node (sent to owning window)
120		// "nodeID"		int32
121		M_NODE_SELECTED,
122
123		// OUTBOUND
124		// describes a selected group (sent to owning window)
125		// "groupID"	int32
126		M_GROUP_SELECTED,
127
128		// INBOUND
129		// requests that the currently selected node/group be broadcast
130		// back to the owning window
131		M_BROADCAST_SELECTION,
132
133		// INBOUND
134		// request to change the selected nodes cycling mode (on/off)
135		// "cycle"		bool
136		M_NODE_CHANGE_CYCLING,
137
138		// INBOUND
139		// request to change the selected nodes run mode
140		// "run_mode"	int32
141		M_NODE_CHANGE_RUN_MODE,
142
143		// INBOUND
144		// request to start/stop the selected node(s) as a time source
145		// instantly
146		// [e.moon 5dec99]
147		M_NODE_START_TIME_SOURCE,
148		M_NODE_STOP_TIME_SOURCE,
149
150		// INBOUND
151		// call BControllable::StartControlPanel for the node specified
152		// in the field "nodeID" (int32)
153		// [c.lenz 24dec99]
154		M_NODE_START_CONTROL_PANEL,
155
156		// INBOUND
157		// set the given group's GROUP_LOCKED flag
158		// [em 1feb00]
159		// "groupID"  int32
160		// "locked"   bool
161		M_GROUP_SET_LOCKED,
162
163		// INBOUND
164		// open ParameterWindow for selected nodes
165		// [c.lenz 17feb2000]
166		M_NODE_TWEAK_PARAMETERS,
167
168		// INBOUND
169		// sent to the RouteWindow for displaying error
170		// messages in the status bar if available
171		// "text"	string
172		// "error"	bool	(optional)
173		M_SHOW_ERROR_MESSAGE
174	};
175
176public:						// *** members
177
178	RouteAppNodeManager* const	manager;
179
180public:						// *** ctor/dtor
181
182							MediaRoutingView(
183								RouteAppNodeManager *nodeManager,
184								BRect frame,
185								const char *name,
186								uint32 resizeMode = B_FOLLOW_ALL_SIDES);
187
188	virtual					~MediaRoutingView();
189
190public:						// *** DiagramView impl
191
192	virtual void			connectionAborted(
193								DiagramEndPoint *fromWhich);
194
195	virtual void			connectionEstablished(
196								DiagramEndPoint *fromWhich,
197								DiagramEndPoint *toWhich);
198
199	DiagramWire			   *createWire(
200								DiagramEndPoint *fromWhich,
201								DiagramEndPoint *woWhich);
202
203	DiagramWire			   *createWire(
204								DiagramEndPoint *fromWhich);
205
206	virtual void			BackgroundMouseDown(
207								BPoint point,
208								uint32 buttons,
209								uint32 clicks);
210
211	virtual void			MessageDropped(
212								BPoint point,
213								BMessage *message);
214
215	virtual void			SelectionChanged();
216
217public:						// *** BView impl
218
219	virtual void			AttachedToWindow();
220
221	virtual void			AllAttached();
222
223	virtual void			DetachedFromWindow();
224
225	virtual void			KeyDown(
226								const char *bytes,
227								int32 count);
228
229	virtual void			Pulse();
230
231public:						// *** BHandler impl
232
233	virtual void			MessageReceived(
234								BMessage *message);
235
236public:						// *** accessors
237
238	layout_t				getLayout() const
239							{ return m_layout; }
240
241public:						// *** operations
242
243	// returns coordinates for a free area where the panel
244	// could be positioned; uses the M_CLEANUP_* settings
245	// and positions producers at the left, consumer at the
246	// right and filters in the middle
247	BPoint					findFreePositionFor(
248								const MediaNodePanel *panel) const;
249
250public:												// *** IStateArchivable
251
252	status_t importState(
253		const BMessage*						archive);
254
255	status_t exportState(
256		BMessage*									archive) const;
257
258	// [e.moon 8dec99] subset support
259	status_t importStateFor(
260		const NodeSetIOContext*		context,
261		const BMessage*						archive);
262
263	status_t exportStateFor(
264		const NodeSetIOContext*		context,
265		BMessage*									archive) const;
266
267protected:					// *** operations
268
269	// adjust the default object sizes to the current
270	// layout and font size and rearrange if necessary
271	void					layoutChanged(
272								layout_t layout);
273
274	// aligns the panels on a grid according to their node_kind
275	void					cleanUp();
276
277	// displays a context menu at a given position
278	void					showContextMenu(
279								BPoint point);
280
281	// will currently display a BAlert; this should change sometime
282	// in the future!
283	void					showErrorMessage(
284								BString message,
285								status_t error);
286
287private:					// *** children management
288
289	// adds a panel representation of a live media node to the view
290	status_t				_addPanelFor(
291								media_node_id id,
292								BPoint point);
293
294	// tries to find the panel to a given media node
295	status_t				_findPanelFor(
296								media_node_id id,
297								MediaNodePanel **outPanel) const;
298
299	// removes the panel of a given media node
300	status_t				_removePanelFor(
301								media_node_id);
302
303	// adds a wire represenation of a media kit connection
304	status_t				_addWireFor(
305								Connection &connection);
306
307	// finds the ui rep of a given Connection object
308	status_t				_findWireFor(
309								uint32	connectionID,
310								MediaWire **wire) const;
311
312	// removes the wire
313	status_t				_removeWireFor(
314								uint32 connectionID);
315
316private:					// *** internal methods
317
318	// iterates through all selected MediaNodePanels and sets the
319	// 'cycling' state for each to cycle
320	void					_changeCyclingForSelection(
321								bool cycle);
322
323	// iterates through all selected MediaNodePanels and sets the
324	// RunMode for each to mode; 0 is interpreted as '(same as group)'
325	void					_changeRunModeForSelection(
326								uint32 mode);
327
328	void					_openInfoWindowsForSelection();
329
330	void					_openParameterWindowsForSelection();
331
332	void					_startControlPanelsForSelection();
333
334	// tries to release every node in the current selection, or to
335	// disconnect wires if those were selected
336	void					_deleteSelection();
337
338	void					_addShortcuts();
339
340	void					_initLayout();
341
342	// populates the view with all nodes currently in the NodeManager
343	void					_initContent();
344
345	void 					_checkDroppedFile(
346								entry_ref *ref,
347								BPoint dropPoint);
348
349	void					_changeBackground(
350								entry_ref *ref);
351
352	void					_changeBackground(
353								rgb_color color);
354
355	// adjust scroll bar ranges
356	void					_adjustScrollBars();
357
358	void					_broadcastSelection() const;
359
360	// find & remove an entry in m_inactiveNodeState
361	status_t				_fetchInactiveNodeState(
362								MediaNodePanel* forPanel,
363								BMessage* outMessage);
364
365	void					_emptyInactiveNodeState();
366
367private:
368
369	// the current layout
370	layout_t				m_layout;
371
372	// current new-group-name index
373	uint32					m_nextGroupNumber;
374
375	// holds the id of the node instantiated last thru d&d
376	media_node_id			m_lastDroppedNode;
377
378	// the point at which above node was dropped
379	BPoint					m_lastDropPoint;
380
381	// holds a pointer to the currently dragged wire (if any)
382	MediaWire			   *m_draggedWire;
383
384	// stores location of the background bitmap (invalid if no
385	// background bitmap has been set.)
386	// [e.moon 1dec99]
387	BEntry					m_backgroundBitmapEntry;
388
389	// state info for currently inactive nodes (cached from importState())
390	BList           m_inactiveNodeState;
391};
392
393__END_CORTEX_NAMESPACE
394#endif /* __MediaRoutingView_H__ */
395