xref: /haiku/src/apps/cortex/MediaRoutingView/MediaNodePanel.cpp (revision c377d661268f0f924b50dcc1c105747d8cedaf1e)
1c284bb0fSMatt Madia /*
2c284bb0fSMatt Madia  * Copyright (c) 1999-2000, Eric Moon.
3c284bb0fSMatt Madia  * All rights reserved.
4c284bb0fSMatt Madia  *
5c284bb0fSMatt Madia  * Redistribution and use in source and binary forms, with or without
6c284bb0fSMatt Madia  * modification, are permitted provided that the following conditions
7c284bb0fSMatt Madia  * are met:
8c284bb0fSMatt Madia  *
9c284bb0fSMatt Madia  * 1. Redistributions of source code must retain the above copyright
10c284bb0fSMatt Madia  *    notice, this list of conditions, and the following disclaimer.
11c284bb0fSMatt Madia  *
12c284bb0fSMatt Madia  * 2. Redistributions in binary form must reproduce the above copyright
13c284bb0fSMatt Madia  *    notice, this list of conditions, and the following disclaimer in the
14c284bb0fSMatt Madia  *    documentation and/or other materials provided with the distribution.
15c284bb0fSMatt Madia  *
16c284bb0fSMatt Madia  * 3. The name of the author may not be used to endorse or promote products
17c284bb0fSMatt Madia  *    derived from this software without specific prior written permission.
18c284bb0fSMatt Madia  *
19c284bb0fSMatt Madia  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20c284bb0fSMatt Madia  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21c284bb0fSMatt Madia  * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22c284bb0fSMatt Madia  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23c284bb0fSMatt Madia  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24c284bb0fSMatt Madia  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25c284bb0fSMatt Madia  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26c284bb0fSMatt Madia  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27c284bb0fSMatt Madia  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28c284bb0fSMatt Madia  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29c284bb0fSMatt Madia  */
30c284bb0fSMatt Madia 
31c284bb0fSMatt Madia 
32a0795c6fSMarcus Overhagen // MediaNodePanel.cpp
33a0795c6fSMarcus Overhagen // c.lenz 10oct99
34a0795c6fSMarcus Overhagen 
35a0795c6fSMarcus Overhagen #include "MediaNodePanel.h"
36a0795c6fSMarcus Overhagen // InfoWindow
37a0795c6fSMarcus Overhagen #include "InfoWindowManager.h"
38a0795c6fSMarcus Overhagen // MediaRoutingView
39a0795c6fSMarcus Overhagen #include "MediaRoutingView.h"
40a0795c6fSMarcus Overhagen #include "MediaWire.h"
41a0795c6fSMarcus Overhagen #include "RouteAppNodeManager.h"
42a0795c6fSMarcus Overhagen // NodeManager
43a0795c6fSMarcus Overhagen #include "NodeRef.h"
44a0795c6fSMarcus Overhagen #include "NodeGroup.h"
45a0795c6fSMarcus Overhagen // ParameterWindow
46a0795c6fSMarcus Overhagen #include "ParameterWindow.h"
47a0795c6fSMarcus Overhagen // Support
48a0795c6fSMarcus Overhagen #include "cortex_ui.h"
49a0795c6fSMarcus Overhagen #include "MediaIcon.h"
50a0795c6fSMarcus Overhagen #include "MediaString.h"
51a0795c6fSMarcus Overhagen // RouteApp
52a0795c6fSMarcus Overhagen #include "RouteWindow.h"
53a0795c6fSMarcus Overhagen // TipManager
54a0795c6fSMarcus Overhagen #include "TipManager.h"
55a0795c6fSMarcus Overhagen 
56a0795c6fSMarcus Overhagen // App Kit
57a0795c6fSMarcus Overhagen #include <Application.h>
58a0795c6fSMarcus Overhagen #include <Roster.h>
59a0795c6fSMarcus Overhagen // Interface Kit
60a0795c6fSMarcus Overhagen #include <MenuItem.h>
61a0795c6fSMarcus Overhagen #include <PopUpMenu.h>
62a0795c6fSMarcus Overhagen // Media Kit
63a0795c6fSMarcus Overhagen #include <MediaDefs.h>
64a0795c6fSMarcus Overhagen #include <MediaRoster.h>
652cba2d56SDancsó Róbert // Locale Kit
662cba2d56SDancsó Róbert #undef B_CATALOG
672cba2d56SDancsó Róbert #define B_CATALOG (&sCatalog)
682cba2d56SDancsó Róbert #include <Catalog.h>
692cba2d56SDancsó Róbert 
702cba2d56SDancsó Róbert #undef B_TRANSLATION_CONTEXT
712cba2d56SDancsó Róbert #define B_TRANSLATION_CONTEXT "MediaNodePanel"
72a0795c6fSMarcus Overhagen 
7323e67806SIthamar R. Adema using namespace std;
7423e67806SIthamar R. Adema 
75a0795c6fSMarcus Overhagen __USE_CORTEX_NAMESPACE
76a0795c6fSMarcus Overhagen 
77a0795c6fSMarcus Overhagen #include <Debug.h>
78a0795c6fSMarcus Overhagen #define D_METHOD(x) //PRINT (x)
79a0795c6fSMarcus Overhagen #define D_MESSAGE(x) //PRINT (x)
80a0795c6fSMarcus Overhagen #define D_DRAW(x) //PRINT (x)
81a0795c6fSMarcus Overhagen 
82bf6a2a2bSNiels Sascha Reedijk static BCatalog sCatalog("x-vnd.Cortex.MediaRoutingView");
832cba2d56SDancsó Róbert 
84a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
85a0795c6fSMarcus Overhagen // constants
86a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
87a0795c6fSMarcus Overhagen 
88a0795c6fSMarcus Overhagen float	MediaNodePanel::M_DEFAULT_WIDTH		= 90.0;
89a0795c6fSMarcus Overhagen float	MediaNodePanel::M_DEFAULT_HEIGHT	= 60.0;
90a0795c6fSMarcus Overhagen float	MediaNodePanel::M_LABEL_H_MARGIN	= 3.0;
91a0795c6fSMarcus Overhagen float	MediaNodePanel::M_LABEL_V_MARGIN	= 3.0;
92a0795c6fSMarcus Overhagen float	MediaNodePanel::M_BODY_H_MARGIN		= 5.0;
93a0795c6fSMarcus Overhagen float	MediaNodePanel::M_BODY_V_MARGIN		= 5.0;
94a0795c6fSMarcus Overhagen 
95a0795c6fSMarcus Overhagen // [e.moon 7dec99]
96a0795c6fSMarcus Overhagen const BPoint MediaNodePanel::s_invalidPosition(-200.0, -200.0);
97a0795c6fSMarcus Overhagen 
98a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
99a0795c6fSMarcus Overhagen // *** ctor/dtor
100a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
101a0795c6fSMarcus Overhagen 
MediaNodePanel(BPoint position,NodeRef * nodeRef)102a0795c6fSMarcus Overhagen MediaNodePanel::MediaNodePanel(
103a0795c6fSMarcus Overhagen 	BPoint position,
104a0795c6fSMarcus Overhagen 	NodeRef *nodeRef)
105a0795c6fSMarcus Overhagen 	: DiagramBox(BRect(position, position + BPoint(M_DEFAULT_WIDTH, M_DEFAULT_HEIGHT))),
106a0795c6fSMarcus Overhagen 	  BHandler(nodeRef->name()),
107a0795c6fSMarcus Overhagen 	  ref(nodeRef),
108a0795c6fSMarcus Overhagen 	  m_bitmap(0),
109a0795c6fSMarcus Overhagen 	  m_icon(0),
110a0795c6fSMarcus Overhagen 	  m_alternatePosition(s_invalidPosition)
111a0795c6fSMarcus Overhagen {
112a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::MediaNodePanel()\n"));
113a0795c6fSMarcus Overhagen 	ASSERT(ref);
114a0795c6fSMarcus Overhagen }
115a0795c6fSMarcus Overhagen 
~MediaNodePanel()116a0795c6fSMarcus Overhagen MediaNodePanel::~MediaNodePanel()
117a0795c6fSMarcus Overhagen {
118a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::~MediaNodePanel()\n"));
119a0795c6fSMarcus Overhagen 	if (m_icon)
120a0795c6fSMarcus Overhagen 	{
121a0795c6fSMarcus Overhagen 		delete m_icon;
122a0795c6fSMarcus Overhagen 	}
123a0795c6fSMarcus Overhagen 	if (m_bitmap)
124a0795c6fSMarcus Overhagen 	{
125a0795c6fSMarcus Overhagen 		delete m_bitmap;
126a0795c6fSMarcus Overhagen 	}
127a0795c6fSMarcus Overhagen }
128a0795c6fSMarcus Overhagen 
129a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
130a0795c6fSMarcus Overhagen // *** derived from DiagramBox
131a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
132a0795c6fSMarcus Overhagen 
attachedToDiagram()133a0795c6fSMarcus Overhagen void MediaNodePanel::attachedToDiagram()
134a0795c6fSMarcus Overhagen {
135a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::attachedToDiagram()\n"));
136a0795c6fSMarcus Overhagen 
137a0795c6fSMarcus Overhagen 	resizeTo(M_DEFAULT_WIDTH, M_DEFAULT_HEIGHT);
138a0795c6fSMarcus Overhagen 	_updateIcon(dynamic_cast<MediaRoutingView *>(view())->getLayout());
139a0795c6fSMarcus Overhagen 	_prepareLabel();
140a0795c6fSMarcus Overhagen 	populateInit();
141a0795c6fSMarcus Overhagen 	arrangeIOJacks();
142a0795c6fSMarcus Overhagen 
143a0795c6fSMarcus Overhagen 	view()->Looper()->AddHandler(this);
144a0795c6fSMarcus Overhagen }
145a0795c6fSMarcus Overhagen 
detachedFromDiagram()146a0795c6fSMarcus Overhagen void MediaNodePanel::detachedFromDiagram()
147a0795c6fSMarcus Overhagen {
148a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::detachedFromDiagram()\n"));
149a0795c6fSMarcus Overhagen 
1505680c33eSIngo Weinhold 	BRect labelRect = m_labelRect.OffsetByCopy(Frame().LeftTop());
151a0795c6fSMarcus Overhagen 	if (m_mouseOverLabel && m_labelTruncated)
152a0795c6fSMarcus Overhagen 	{
153a0795c6fSMarcus Overhagen 		TipManager *tips = TipManager::Instance();
154a0795c6fSMarcus Overhagen 		tips->hideTip(view()->ConvertToScreen(labelRect));
155a0795c6fSMarcus Overhagen 	}
156a0795c6fSMarcus Overhagen 
157a0795c6fSMarcus Overhagen 	view()->Looper()->RemoveHandler(this);
158a0795c6fSMarcus Overhagen }
159a0795c6fSMarcus Overhagen 
DrawBox()1605680c33eSIngo Weinhold void MediaNodePanel::DrawBox()
161a0795c6fSMarcus Overhagen {
1625680c33eSIngo Weinhold 	D_DRAW(("MediaNodePanel::DrawBox()\n"));
163a0795c6fSMarcus Overhagen 	if (m_bitmap)
164a0795c6fSMarcus Overhagen 	{
1655680c33eSIngo Weinhold 		view()->DrawBitmap(m_bitmap, Frame().LeftTop());
166a0795c6fSMarcus Overhagen 	}
167a0795c6fSMarcus Overhagen }
168a0795c6fSMarcus Overhagen 
MouseDown(BPoint point,uint32 buttons,uint32 clicks)1695680c33eSIngo Weinhold void MediaNodePanel::MouseDown(
170a0795c6fSMarcus Overhagen 	BPoint point,
171a0795c6fSMarcus Overhagen 	uint32 buttons,
172a0795c6fSMarcus Overhagen 	uint32 clicks)
173a0795c6fSMarcus Overhagen {
1745680c33eSIngo Weinhold 	D_METHOD(("MediaNodePanel::MouseDown()\n"));
175a0795c6fSMarcus Overhagen 
1765680c33eSIngo Weinhold 	_inherited::MouseDown(point, buttons, clicks);
177a0795c6fSMarcus Overhagen 
178a0795c6fSMarcus Overhagen 	// +++ REALLY BAD WORKAROUND
179595c89bcSAxel Dörfler 	MediaJack *jack = dynamic_cast<MediaJack *>(_LastItemUnder());
1805680c33eSIngo Weinhold 	if (jack && jack->Frame().Contains(point))
181a0795c6fSMarcus Overhagen 	{
182a0795c6fSMarcus Overhagen 		return;
183a0795c6fSMarcus Overhagen 	}
184a0795c6fSMarcus Overhagen 
185a0795c6fSMarcus Overhagen 	switch (buttons) {
186a0795c6fSMarcus Overhagen 		case B_PRIMARY_MOUSE_BUTTON:
187a0795c6fSMarcus Overhagen 		{
188a0795c6fSMarcus Overhagen 			if (clicks == 2) {
189a0795c6fSMarcus Overhagen 				if (ref->kind() & B_CONTROLLABLE) {
190a0795c6fSMarcus Overhagen 					BMessage message(MediaRoutingView::M_NODE_TWEAK_PARAMETERS);
191a0795c6fSMarcus Overhagen 					DiagramView* v = view();
192a0795c6fSMarcus Overhagen 					BMessenger(v).SendMessage(&message);
193a0795c6fSMarcus Overhagen 				}
194a0795c6fSMarcus Overhagen 			}
195a0795c6fSMarcus Overhagen 			break;
196a0795c6fSMarcus Overhagen 		}
197a0795c6fSMarcus Overhagen 		case B_SECONDARY_MOUSE_BUTTON:
198a0795c6fSMarcus Overhagen 		{
199a0795c6fSMarcus Overhagen 			if (clicks == 1) {
200a0795c6fSMarcus Overhagen 				showContextMenu(point);
201a0795c6fSMarcus Overhagen 			}
202a0795c6fSMarcus Overhagen 			break;
203a0795c6fSMarcus Overhagen 		}
204a0795c6fSMarcus Overhagen 	}
205a0795c6fSMarcus Overhagen }
206a0795c6fSMarcus Overhagen 
MouseOver(BPoint point,uint32 transit)2075680c33eSIngo Weinhold void MediaNodePanel::MouseOver(
208a0795c6fSMarcus Overhagen 	BPoint point,
209a0795c6fSMarcus Overhagen 	uint32 transit)
210a0795c6fSMarcus Overhagen {
2115680c33eSIngo Weinhold 	D_METHOD(("MediaNodePanel::MouseOver()\n"));
2125680c33eSIngo Weinhold 	_inherited::MouseOver(point, transit);
213a0795c6fSMarcus Overhagen 
214a0795c6fSMarcus Overhagen 	switch (transit)
215a0795c6fSMarcus Overhagen 	{
216a0795c6fSMarcus Overhagen 		case B_ENTERED_VIEW:
217a0795c6fSMarcus Overhagen 		{
218a0795c6fSMarcus Overhagen 			break;
219a0795c6fSMarcus Overhagen 		}
220a0795c6fSMarcus Overhagen 		case B_INSIDE_VIEW:
221a0795c6fSMarcus Overhagen 		{
2225680c33eSIngo Weinhold 			BRect labelRect = m_labelRect.OffsetByCopy(Frame().LeftTop());
223a0795c6fSMarcus Overhagen 			if (labelRect.Contains(point))
224a0795c6fSMarcus Overhagen 			{
225a0795c6fSMarcus Overhagen 				if (!m_mouseOverLabel && m_labelTruncated)
226a0795c6fSMarcus Overhagen 				{
227a0795c6fSMarcus Overhagen 					TipManager *tips = TipManager::Instance();
228a0795c6fSMarcus Overhagen 					tips->showTip(m_fullLabel.String(), view()->ConvertToScreen(labelRect));
229a0795c6fSMarcus Overhagen 					m_mouseOverLabel = true;
230a0795c6fSMarcus Overhagen 				}
231a0795c6fSMarcus Overhagen 			}
232a0795c6fSMarcus Overhagen 			else
233a0795c6fSMarcus Overhagen 			{
234a0795c6fSMarcus Overhagen 				m_mouseOverLabel = false;
235a0795c6fSMarcus Overhagen 			}
236a0795c6fSMarcus Overhagen 			break;
237a0795c6fSMarcus Overhagen 		}
238a0795c6fSMarcus Overhagen 		case B_EXITED_VIEW:
239a0795c6fSMarcus Overhagen 		{
240a0795c6fSMarcus Overhagen 			m_mouseOverLabel = false;
241a0795c6fSMarcus Overhagen 			break;
242a0795c6fSMarcus Overhagen 		}
243a0795c6fSMarcus Overhagen 	}
244a0795c6fSMarcus Overhagen }
245a0795c6fSMarcus Overhagen 
MessageDropped(BPoint point,BMessage * message)2465680c33eSIngo Weinhold void MediaNodePanel::MessageDropped(
247a0795c6fSMarcus Overhagen 	BPoint point,
248a0795c6fSMarcus Overhagen 	BMessage *message)
249a0795c6fSMarcus Overhagen {
2505680c33eSIngo Weinhold 	D_METHOD(("MediaNodePanel::MessageDropped()\n"));
251a0795c6fSMarcus Overhagen 
252a0795c6fSMarcus Overhagen 	// +++ REALLY BAD WORKAROUND
253595c89bcSAxel Dörfler 	MediaJack *jack = dynamic_cast<MediaJack *>(ItemUnder(point));
254a0795c6fSMarcus Overhagen 	if (jack)
255a0795c6fSMarcus Overhagen 	{
2565680c33eSIngo Weinhold 		jack->MessageDropped(point, message);
257a0795c6fSMarcus Overhagen 		return;
258a0795c6fSMarcus Overhagen 	}
259a0795c6fSMarcus Overhagen 	else
260a0795c6fSMarcus Overhagen 	{
261a0795c6fSMarcus Overhagen 		be_app->SetCursor(B_HAND_CURSOR);
262a0795c6fSMarcus Overhagen 	}
263a0795c6fSMarcus Overhagen }
264a0795c6fSMarcus Overhagen 
selected()265a0795c6fSMarcus Overhagen void MediaNodePanel::selected()
266a0795c6fSMarcus Overhagen {
267a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::selected()\n"));
268a0795c6fSMarcus Overhagen 	_updateBitmap();
269a0795c6fSMarcus Overhagen }
270a0795c6fSMarcus Overhagen 
deselected()271a0795c6fSMarcus Overhagen void MediaNodePanel::deselected()
272a0795c6fSMarcus Overhagen {
273a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::deselected()\n"));
274a0795c6fSMarcus Overhagen 	_updateBitmap();
275a0795c6fSMarcus Overhagen }
276a0795c6fSMarcus Overhagen 
277a0795c6fSMarcus Overhagen // ---------------------------------------------------------------- //
278a0795c6fSMarcus Overhagen // *** updating
279a0795c6fSMarcus Overhagen // ---------------------------------------------------------------- //
280a0795c6fSMarcus Overhagen 
layoutChanged(int32 layout)281a0795c6fSMarcus Overhagen void MediaNodePanel::layoutChanged(
282a0795c6fSMarcus Overhagen 	int32 layout)
283a0795c6fSMarcus Overhagen {
284a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::layoutChanged()\n"));
285a0795c6fSMarcus Overhagen 
2865680c33eSIngo Weinhold 	BPoint p = Frame().LeftTop();
287a0795c6fSMarcus Overhagen 	if (m_alternatePosition == s_invalidPosition)
288a0795c6fSMarcus Overhagen 	{
289a0795c6fSMarcus Overhagen 		m_alternatePosition = dynamic_cast<MediaRoutingView *>
290a0795c6fSMarcus Overhagen 							  (view())->findFreePositionFor(this);
291a0795c6fSMarcus Overhagen 	}
292a0795c6fSMarcus Overhagen 	moveTo(m_alternatePosition);
293a0795c6fSMarcus Overhagen 	m_alternatePosition = p;
294a0795c6fSMarcus Overhagen 
295a0795c6fSMarcus Overhagen 	resizeTo(M_DEFAULT_WIDTH, M_DEFAULT_HEIGHT);
296595c89bcSAxel Dörfler 	for (uint32 i = 0; i < CountItems(); i++)
297a0795c6fSMarcus Overhagen 	{
298595c89bcSAxel Dörfler 		MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
299a0795c6fSMarcus Overhagen 		jack->layoutChanged(layout);
300a0795c6fSMarcus Overhagen 	}
301a0795c6fSMarcus Overhagen 	_updateIcon(layout);
302a0795c6fSMarcus Overhagen 	_prepareLabel();
303a0795c6fSMarcus Overhagen 	arrangeIOJacks();
304a0795c6fSMarcus Overhagen 	_updateBitmap();
305a0795c6fSMarcus Overhagen }
306a0795c6fSMarcus Overhagen 
populateInit()307a0795c6fSMarcus Overhagen void MediaNodePanel::populateInit()
308a0795c6fSMarcus Overhagen {
309a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::populateInit()\n"));
310a0795c6fSMarcus Overhagen 	if (ref->kind() & B_BUFFER_CONSUMER)
311a0795c6fSMarcus Overhagen 	{
312a0795c6fSMarcus Overhagen 		vector<media_input> freeInputs;
313a0795c6fSMarcus Overhagen 		ref->getFreeInputs(freeInputs);
314a0795c6fSMarcus Overhagen 		for (uint32 i = 0; i < freeInputs.size(); i++)
315a0795c6fSMarcus Overhagen 		{
316595c89bcSAxel Dörfler 			AddItem(new MediaJack(freeInputs[i]));
317a0795c6fSMarcus Overhagen 		}
318a0795c6fSMarcus Overhagen 	}
319a0795c6fSMarcus Overhagen 	if (ref->kind() & B_BUFFER_PRODUCER)
320a0795c6fSMarcus Overhagen 	{
321a0795c6fSMarcus Overhagen 		vector<media_output> freeOutputs;
322a0795c6fSMarcus Overhagen 		ref->getFreeOutputs(freeOutputs);
323a0795c6fSMarcus Overhagen 		for (uint32 i = 0; i < freeOutputs.size(); i++)
324a0795c6fSMarcus Overhagen 		{
325595c89bcSAxel Dörfler 			AddItem(new MediaJack(freeOutputs[i]));
326a0795c6fSMarcus Overhagen 		}
327a0795c6fSMarcus Overhagen 	}
328a0795c6fSMarcus Overhagen }
329a0795c6fSMarcus Overhagen 
updateIOJacks()330a0795c6fSMarcus Overhagen void MediaNodePanel::updateIOJacks()
331a0795c6fSMarcus Overhagen {
332a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::updateIOJacks()\n"));
333a0795c6fSMarcus Overhagen 
334a0795c6fSMarcus Overhagen 	// remove all free inputs/outputs, they may be outdated
335595c89bcSAxel Dörfler 	for (uint32 i = 0; i < CountItems(); i++)
336a0795c6fSMarcus Overhagen 	{
337595c89bcSAxel Dörfler 		MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
338a0795c6fSMarcus Overhagen 		if (jack && !jack->isConnected())
339a0795c6fSMarcus Overhagen 		{
340595c89bcSAxel Dörfler 			RemoveItem(jack);
341a0795c6fSMarcus Overhagen 			delete jack;
342a0795c6fSMarcus Overhagen 			i--; // account for reindexing in the BList
343a0795c6fSMarcus Overhagen 		}
344a0795c6fSMarcus Overhagen 	}
345a0795c6fSMarcus Overhagen 
346a0795c6fSMarcus Overhagen 	// add free inputs
347a0795c6fSMarcus Overhagen 	if (ref->kind() & B_BUFFER_CONSUMER)
348a0795c6fSMarcus Overhagen 	{
349a0795c6fSMarcus Overhagen 		vector<media_input> freeInputs;
350a0795c6fSMarcus Overhagen 		ref->getFreeInputs(freeInputs);
351a0795c6fSMarcus Overhagen 		for (uint32 i = 0; i < freeInputs.size(); i++)
352a0795c6fSMarcus Overhagen 		{
353f30ba677SMurai Takashi 			AddItem(new MediaJack(freeInputs[i]));
354a0795c6fSMarcus Overhagen 		}
355a0795c6fSMarcus Overhagen 	}
356a0795c6fSMarcus Overhagen 
357a0795c6fSMarcus Overhagen 	// add free outputs
358a0795c6fSMarcus Overhagen 	if (ref->kind() & B_BUFFER_PRODUCER)
359a0795c6fSMarcus Overhagen 	{
360a0795c6fSMarcus Overhagen 		vector<media_output> freeOutputs;
361a0795c6fSMarcus Overhagen 		ref->getFreeOutputs(freeOutputs);
362a0795c6fSMarcus Overhagen 		for (uint32 i = 0; i < freeOutputs.size(); i++)
363a0795c6fSMarcus Overhagen 		{
364f30ba677SMurai Takashi 			AddItem(new MediaJack(freeOutputs[i]));
365a0795c6fSMarcus Overhagen 		}
366a0795c6fSMarcus Overhagen 	}
367a0795c6fSMarcus Overhagen 
368a0795c6fSMarcus Overhagen 	// the supported media types might have changed -> this could
369a0795c6fSMarcus Overhagen 	// require changing the icon
370a0795c6fSMarcus Overhagen 	_updateIcon(dynamic_cast<MediaRoutingView *>(view())->getLayout());
371a0795c6fSMarcus Overhagen }
372a0795c6fSMarcus Overhagen 
arrangeIOJacks()373a0795c6fSMarcus Overhagen void MediaNodePanel::arrangeIOJacks()
374a0795c6fSMarcus Overhagen {
375a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::arrangeIOJacks()\n"));
376595c89bcSAxel Dörfler 	SortItems(DiagramItem::M_ENDPOINT, &compareTypeAndID);
377a0795c6fSMarcus Overhagen 
378a0795c6fSMarcus Overhagen 	switch (dynamic_cast<MediaRoutingView *>(view())->getLayout())
379a0795c6fSMarcus Overhagen 	{
380a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_ICON_VIEW:
381a0795c6fSMarcus Overhagen 		{
382a0795c6fSMarcus Overhagen 			BRegion updateRegion;
383a0795c6fSMarcus Overhagen 			float align = 1.0;
384595c89bcSAxel Dörfler 			view()->GetItemAlignment(0, &align);
385a0795c6fSMarcus Overhagen 
386a0795c6fSMarcus Overhagen 			// adjust this panel's size
387a0795c6fSMarcus Overhagen 			int32 numInputs = 0, numOutputs = 0;
388595c89bcSAxel Dörfler 			for (uint32 i = 0; i < CountItems(); i++)
389a0795c6fSMarcus Overhagen 			{
390595c89bcSAxel Dörfler 				MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
391a0795c6fSMarcus Overhagen 				if (jack)
392a0795c6fSMarcus Overhagen 				{
393a0795c6fSMarcus Overhagen 					if (jack->isInput())
394a0795c6fSMarcus Overhagen 					{
395a0795c6fSMarcus Overhagen 						numInputs++;
396a0795c6fSMarcus Overhagen 					}
397a0795c6fSMarcus Overhagen 					if (jack->isOutput())
398a0795c6fSMarcus Overhagen 					{
399a0795c6fSMarcus Overhagen 						numOutputs++;
400a0795c6fSMarcus Overhagen 					}
401a0795c6fSMarcus Overhagen 				}
402a0795c6fSMarcus Overhagen 			}
403a0795c6fSMarcus Overhagen 			float minHeight = MediaJack::M_DEFAULT_HEIGHT + MediaJack::M_DEFAULT_GAP;
404a0795c6fSMarcus Overhagen 			minHeight *= numInputs > numOutputs ? numInputs : numOutputs;
405a0795c6fSMarcus Overhagen 			minHeight += m_labelRect.Height();
406a0795c6fSMarcus Overhagen 			minHeight += 2 * MediaJack::M_DEFAULT_GAP;
407a0795c6fSMarcus Overhagen 			minHeight = ((int)minHeight / (int)align) * align + align;
4085680c33eSIngo Weinhold 			if ((Frame().Height() < minHeight)
4095680c33eSIngo Weinhold 			 || ((Frame().Height() > minHeight)
410a0795c6fSMarcus Overhagen 			 && (minHeight >= MediaNodePanel::M_DEFAULT_HEIGHT)))
411a0795c6fSMarcus Overhagen 			{
4125680c33eSIngo Weinhold 				updateRegion.Include(Frame());
4135680c33eSIngo Weinhold 				resizeTo(Frame().Width(), minHeight);
4145680c33eSIngo Weinhold 				updateRegion.Include(Frame());
415a0795c6fSMarcus Overhagen 				_prepareLabel();
416a0795c6fSMarcus Overhagen 			}
417a0795c6fSMarcus Overhagen 
418a0795c6fSMarcus Overhagen 			// adjust the placement of the jacks
419a0795c6fSMarcus Overhagen 			BRect r = m_bodyRect;
420a0795c6fSMarcus Overhagen 			r.bottom -= M_BODY_V_MARGIN;
421a0795c6fSMarcus Overhagen 			float inputOffset = 0.0, outputOffset = 0.0;
4225680c33eSIngo Weinhold 			float center = Frame().top + r.top + (r.Height() / 2.0);
423a0795c6fSMarcus Overhagen 			center += MediaJack::M_DEFAULT_GAP - (MediaJack::M_DEFAULT_HEIGHT / 2.0);
424a0795c6fSMarcus Overhagen 			center = ((int)center / (int)align) * align;
425a0795c6fSMarcus Overhagen 			if (numInputs)
426a0795c6fSMarcus Overhagen 			{
427a0795c6fSMarcus Overhagen 				if (numInputs % 2) // odd number of inputs
428a0795c6fSMarcus Overhagen 				{
429a0795c6fSMarcus Overhagen 					inputOffset = center - (numInputs / 2) * (MediaJack::M_DEFAULT_HEIGHT + MediaJack::M_DEFAULT_GAP);
430a0795c6fSMarcus Overhagen 				}
431a0795c6fSMarcus Overhagen 				else // even number of inputs
432a0795c6fSMarcus Overhagen 				{
433a0795c6fSMarcus Overhagen 					inputOffset = center - ((numInputs + 1) / 2) * (MediaJack::M_DEFAULT_HEIGHT + MediaJack::M_DEFAULT_GAP);
434a0795c6fSMarcus Overhagen 				}
435a0795c6fSMarcus Overhagen 			}
436a0795c6fSMarcus Overhagen 			if (numOutputs)
437a0795c6fSMarcus Overhagen 			{
438a0795c6fSMarcus Overhagen 				if (numOutputs % 2) // odd number of outputs
439a0795c6fSMarcus Overhagen 				{
440a0795c6fSMarcus Overhagen 					outputOffset = center - (numOutputs / 2) * (MediaJack::M_DEFAULT_HEIGHT + MediaJack::M_DEFAULT_GAP);
441a0795c6fSMarcus Overhagen 				}
442a0795c6fSMarcus Overhagen 				else // even number of outputs
443a0795c6fSMarcus Overhagen 				{
444a0795c6fSMarcus Overhagen 					outputOffset = center - ((numOutputs + 1) / 2) * (MediaJack::M_DEFAULT_HEIGHT + MediaJack::M_DEFAULT_GAP);
445a0795c6fSMarcus Overhagen 				}
446a0795c6fSMarcus Overhagen 			}
447595c89bcSAxel Dörfler 			for (uint32 i = 0; i < CountItems(); i++)
448a0795c6fSMarcus Overhagen 			{
449595c89bcSAxel Dörfler 				MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
450a0795c6fSMarcus Overhagen 				if (jack)
451a0795c6fSMarcus Overhagen 				{
452a0795c6fSMarcus Overhagen 					if (jack->isInput())
453a0795c6fSMarcus Overhagen 					{
4545680c33eSIngo Weinhold 						jack->setPosition(inputOffset, Frame().left, Frame().right, &updateRegion);
4555680c33eSIngo Weinhold 						inputOffset += jack->Frame().Height() + MediaJack::M_DEFAULT_GAP;
456a0795c6fSMarcus Overhagen 					}
457a0795c6fSMarcus Overhagen 					if (jack->isOutput())
458a0795c6fSMarcus Overhagen 					{
4595680c33eSIngo Weinhold 						jack->setPosition(outputOffset, Frame().left, Frame().right, &updateRegion);
4605680c33eSIngo Weinhold 						outputOffset += jack->Frame().Height() + MediaJack::M_DEFAULT_GAP;
461a0795c6fSMarcus Overhagen 					}
462a0795c6fSMarcus Overhagen 				}
463a0795c6fSMarcus Overhagen 			}
464a0795c6fSMarcus Overhagen 			for (int32 i = 0; i < updateRegion.CountRects(); i++)
465a0795c6fSMarcus Overhagen 			{
466a0795c6fSMarcus Overhagen 				view()->Invalidate(updateRegion.RectAt(i));
467a0795c6fSMarcus Overhagen 			}
468a0795c6fSMarcus Overhagen 			break;
469a0795c6fSMarcus Overhagen 		}
470a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_MINI_ICON_VIEW:
471a0795c6fSMarcus Overhagen 		{
472a0795c6fSMarcus Overhagen 			BRegion updateRegion;
473a0795c6fSMarcus Overhagen 			float align = 1.0;
474595c89bcSAxel Dörfler 			view()->GetItemAlignment(&align, 0);
475a0795c6fSMarcus Overhagen 
476a0795c6fSMarcus Overhagen 			// adjust this panel's size
477a0795c6fSMarcus Overhagen 			int32 numInputs = 0, numOutputs = 0;
478595c89bcSAxel Dörfler 			for (uint32 i = 0; i < CountItems(); i++)
479a0795c6fSMarcus Overhagen 			{
480595c89bcSAxel Dörfler 				MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
481a0795c6fSMarcus Overhagen 				if (jack)
482a0795c6fSMarcus Overhagen 				{
483a0795c6fSMarcus Overhagen 					if (jack->isInput())
484a0795c6fSMarcus Overhagen 					{
485a0795c6fSMarcus Overhagen 						numInputs++;
486a0795c6fSMarcus Overhagen 					}
487a0795c6fSMarcus Overhagen 					if (jack->isOutput())
488a0795c6fSMarcus Overhagen 					{
489a0795c6fSMarcus Overhagen 						numOutputs++;
490a0795c6fSMarcus Overhagen 					}
491a0795c6fSMarcus Overhagen 				}
492a0795c6fSMarcus Overhagen 			}
493a0795c6fSMarcus Overhagen 			float minWidth = MediaJack::M_DEFAULT_WIDTH + MediaJack::M_DEFAULT_GAP;
494a0795c6fSMarcus Overhagen 			minWidth *= numInputs > numOutputs ? numInputs : numOutputs;
495a0795c6fSMarcus Overhagen 			minWidth += m_bodyRect.Width();
496a0795c6fSMarcus Overhagen 			minWidth += 2 * MediaJack::M_DEFAULT_GAP;
497a0795c6fSMarcus Overhagen 			minWidth = ((int)minWidth / (int)align) * align + align;
4985680c33eSIngo Weinhold 			if ((Frame().Width() < minWidth)
4995680c33eSIngo Weinhold 			 || ((Frame().Width() > minWidth)
500a0795c6fSMarcus Overhagen 			 && (minWidth >= MediaNodePanel::M_DEFAULT_WIDTH)))
501a0795c6fSMarcus Overhagen 			{
5025680c33eSIngo Weinhold 				updateRegion.Include(Frame());
5035680c33eSIngo Weinhold 				resizeTo(minWidth, Frame().Height());
5045680c33eSIngo Weinhold 				updateRegion.Include(Frame());
505a0795c6fSMarcus Overhagen 				_prepareLabel();
506a0795c6fSMarcus Overhagen 			}
507a0795c6fSMarcus Overhagen 			// adjust the placement of the jacks
508a0795c6fSMarcus Overhagen 			float inputOffset = 0.0, outputOffset = 0.0;
5095680c33eSIngo Weinhold 			float center = Frame().left + m_labelRect.left + (m_labelRect.Width() / 2.0);
510a0795c6fSMarcus Overhagen 			center += MediaJack::M_DEFAULT_GAP - (MediaJack::M_DEFAULT_WIDTH / 2.0);
511a0795c6fSMarcus Overhagen 			center = ((int)center / (int)align) * align;
512a0795c6fSMarcus Overhagen 			if (numInputs)
513a0795c6fSMarcus Overhagen 			{
514a0795c6fSMarcus Overhagen 				if (numInputs % 2) // odd number of inputs
515a0795c6fSMarcus Overhagen 				{
516a0795c6fSMarcus Overhagen 					inputOffset = center - (numInputs / 2) * (MediaJack::M_DEFAULT_WIDTH + MediaJack::M_DEFAULT_GAP);
517a0795c6fSMarcus Overhagen 				}
518a0795c6fSMarcus Overhagen 				else // even number of inputs
519a0795c6fSMarcus Overhagen 				{
520a0795c6fSMarcus Overhagen 					inputOffset = center - ((numInputs + 1) / 2) * (MediaJack::M_DEFAULT_WIDTH + MediaJack::M_DEFAULT_GAP);
521a0795c6fSMarcus Overhagen 				}
522a0795c6fSMarcus Overhagen 			}
523a0795c6fSMarcus Overhagen 			if (numOutputs)
524a0795c6fSMarcus Overhagen 			{
525a0795c6fSMarcus Overhagen 				if (numOutputs % 2) // odd number of outputs
526a0795c6fSMarcus Overhagen 				{
527a0795c6fSMarcus Overhagen 					outputOffset = center - (numOutputs / 2) * (MediaJack::M_DEFAULT_WIDTH + MediaJack::M_DEFAULT_GAP);
528a0795c6fSMarcus Overhagen 				}
529a0795c6fSMarcus Overhagen 				else // even number of outputs
530a0795c6fSMarcus Overhagen 				{
531a0795c6fSMarcus Overhagen 					outputOffset = center - ((numOutputs + 1) / 2) * (MediaJack::M_DEFAULT_WIDTH + MediaJack::M_DEFAULT_GAP);
532a0795c6fSMarcus Overhagen 				}
533a0795c6fSMarcus Overhagen 			}
534595c89bcSAxel Dörfler 			for (uint32 i = 0; i < CountItems(); i++)
535a0795c6fSMarcus Overhagen 			{
536595c89bcSAxel Dörfler 				MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
537a0795c6fSMarcus Overhagen 				if (jack)
538a0795c6fSMarcus Overhagen 				{
539a0795c6fSMarcus Overhagen 					if (jack->isInput())
540a0795c6fSMarcus Overhagen 					{
5415680c33eSIngo Weinhold 						jack->setPosition(inputOffset, Frame().top, Frame().bottom, &updateRegion);
5425680c33eSIngo Weinhold 						inputOffset += jack->Frame().Width() + MediaJack::M_DEFAULT_GAP;
543a0795c6fSMarcus Overhagen 					}
544a0795c6fSMarcus Overhagen 					if (jack->isOutput())
545a0795c6fSMarcus Overhagen 					{
5465680c33eSIngo Weinhold 						jack->setPosition(outputOffset, Frame().top, Frame().bottom, &updateRegion);
5475680c33eSIngo Weinhold 						outputOffset += jack->Frame().Width() + MediaJack::M_DEFAULT_GAP;
548a0795c6fSMarcus Overhagen 					}
549a0795c6fSMarcus Overhagen 				}
550a0795c6fSMarcus Overhagen 			}
551a0795c6fSMarcus Overhagen 			for (int32 i = 0; i < updateRegion.CountRects(); i++)
552a0795c6fSMarcus Overhagen 			{
553a0795c6fSMarcus Overhagen 				view()->Invalidate(updateRegion.RectAt(i));
554a0795c6fSMarcus Overhagen 			}
555a0795c6fSMarcus Overhagen 			break;
556a0795c6fSMarcus Overhagen 		}
557a0795c6fSMarcus Overhagen 	}
558a0795c6fSMarcus Overhagen 	_updateBitmap();
559a0795c6fSMarcus Overhagen }
560a0795c6fSMarcus Overhagen 
showContextMenu(BPoint point)561a0795c6fSMarcus Overhagen void MediaNodePanel::showContextMenu(
562a0795c6fSMarcus Overhagen 	BPoint point)
563a0795c6fSMarcus Overhagen {
564a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::showContextMenu()\n"));
565a0795c6fSMarcus Overhagen 
566a0795c6fSMarcus Overhagen 	BPopUpMenu *menu = new BPopUpMenu("MediaNodePanel PopUp", false, false, B_ITEMS_IN_COLUMN);
567a0795c6fSMarcus Overhagen 	menu->SetFont(be_plain_font);
568a0795c6fSMarcus Overhagen 
569a0795c6fSMarcus Overhagen 	BMenuItem *item;
570a0795c6fSMarcus Overhagen 	BMessage *message;
571a0795c6fSMarcus Overhagen 
572a0795c6fSMarcus Overhagen 	// add the "Tweak Parameters" item
573a0795c6fSMarcus Overhagen 	message = new BMessage(MediaRoutingView::M_NODE_TWEAK_PARAMETERS);
5742cba2d56SDancsó Róbert 	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Tweak parameters"),
5752cba2d56SDancsó Róbert 		message, 'P'));
576a0795c6fSMarcus Overhagen 	if (!(ref->kind() & B_CONTROLLABLE))
577a0795c6fSMarcus Overhagen 	{
578a0795c6fSMarcus Overhagen 		item->SetEnabled(false);
579a0795c6fSMarcus Overhagen 	}
580a0795c6fSMarcus Overhagen 
581a0795c6fSMarcus Overhagen 	message = new BMessage(InfoWindowManager::M_INFO_WINDOW_REQUESTED);
582a0795c6fSMarcus Overhagen 	message->AddInt32("nodeID", ref->id());
5832cba2d56SDancsó Róbert 	menu->AddItem(new BMenuItem(B_TRANSLATE("Get info"), message, 'I'));
584a0795c6fSMarcus Overhagen 	menu->AddSeparatorItem();
585a0795c6fSMarcus Overhagen 
5862cba2d56SDancsó Róbert 	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Release"),
5872cba2d56SDancsó Róbert 		new BMessage(MediaRoutingView::M_DELETE_SELECTION), 'T'));
588a0795c6fSMarcus Overhagen 	if (!ref->isInternal())
589a0795c6fSMarcus Overhagen 	{
590a0795c6fSMarcus Overhagen 		item->SetEnabled(false);
591a0795c6fSMarcus Overhagen 	}
592a0795c6fSMarcus Overhagen 	menu->AddSeparatorItem();
593a0795c6fSMarcus Overhagen 
594a0795c6fSMarcus Overhagen 	// add the "Cycle" item
595a0795c6fSMarcus Overhagen 	message = new BMessage(MediaRoutingView::M_NODE_CHANGE_CYCLING);
596a0795c6fSMarcus Overhagen 	message->AddBool("cycle", !ref->isCycling());
5972cba2d56SDancsó Róbert 	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Cycle"), message));
598a0795c6fSMarcus Overhagen 	item->SetMarked(ref->isCycling());
599a0795c6fSMarcus Overhagen 	if (ref->flags() & NodeRef::NO_SEEK)
600a0795c6fSMarcus Overhagen 	{
601a0795c6fSMarcus Overhagen 		item->SetEnabled(false);
602a0795c6fSMarcus Overhagen 	}
603a0795c6fSMarcus Overhagen 
604a0795c6fSMarcus Overhagen 	// add the "Run Mode" sub menu
6052cba2d56SDancsó Róbert 	BMenu *subMenu = new BMenu(B_TRANSLATE("Run mode"));
606a0795c6fSMarcus Overhagen 	subMenu->SetFont(be_plain_font);
607a0795c6fSMarcus Overhagen 	for (uint32 runMode = 1; runMode <= BMediaNode::B_RECORDING; runMode++)
608a0795c6fSMarcus Overhagen 	{
609a0795c6fSMarcus Overhagen 		BString itemName = MediaString::getStringFor(static_cast<BMediaNode::run_mode>
610a0795c6fSMarcus Overhagen 													 (runMode));
611a0795c6fSMarcus Overhagen 		message = new BMessage(MediaRoutingView::M_NODE_CHANGE_RUN_MODE);
612a0795c6fSMarcus Overhagen 		message->AddInt32("run_mode", runMode);
613a0795c6fSMarcus Overhagen 		subMenu->AddItem(item = new BMenuItem(itemName.String(), message));
614a0795c6fSMarcus Overhagen 		if (ref->runMode() == runMode)
615a0795c6fSMarcus Overhagen 		{
616a0795c6fSMarcus Overhagen 			item->SetMarked(true);
617a0795c6fSMarcus Overhagen 		}
618a0795c6fSMarcus Overhagen 		else if ((ref->runMode() == 0)
619a0795c6fSMarcus Overhagen 			  && (ref->group()) && (ref->group()->runMode() == BMediaNode::run_mode(runMode)))
620a0795c6fSMarcus Overhagen 		{
621a0795c6fSMarcus Overhagen 			item->SetMarked(true);
622a0795c6fSMarcus Overhagen 		}
623a0795c6fSMarcus Overhagen 	}
624a0795c6fSMarcus Overhagen 	subMenu->AddSeparatorItem();
625a0795c6fSMarcus Overhagen 	message = new BMessage(MediaRoutingView::M_NODE_CHANGE_RUN_MODE);
626a0795c6fSMarcus Overhagen 	message->AddInt32("run_mode", 0);
6272cba2d56SDancsó Róbert 	subMenu->AddItem(
6282cba2d56SDancsó Róbert 		item = new BMenuItem(B_TRANSLATE("(same as group)"), message));
629a0795c6fSMarcus Overhagen 	if (ref->group() == 0)
630a0795c6fSMarcus Overhagen 	{
631a0795c6fSMarcus Overhagen 		item->SetEnabled(false);
632a0795c6fSMarcus Overhagen 	}
633a0795c6fSMarcus Overhagen 	else if ((ref->runMode() < 1) && (ref->group()->runMode() > 0))
634a0795c6fSMarcus Overhagen 	{
635a0795c6fSMarcus Overhagen 		item->SetMarked(true);
636a0795c6fSMarcus Overhagen 	}
637a0795c6fSMarcus Overhagen 	menu->AddItem(subMenu);
638a0795c6fSMarcus Overhagen 	subMenu->SetTargetForItems(view());
639a0795c6fSMarcus Overhagen 
640a0795c6fSMarcus Overhagen 	// [c.lenz 24dec99] hide rarely used commands in a 'Advanced' submenu
6412cba2d56SDancsó Róbert 	subMenu = new BMenu(B_TRANSLATE("Advanced"));
642a0795c6fSMarcus Overhagen 	subMenu->SetFont(be_plain_font);
643a0795c6fSMarcus Overhagen 	// [e.moon 5dec99] ad-hoc timesource support
644a0795c6fSMarcus Overhagen 	if(ref->kind() & B_TIME_SOURCE) {
645a0795c6fSMarcus Overhagen 		message = new BMessage(MediaRoutingView::M_NODE_START_TIME_SOURCE);
646a0795c6fSMarcus Overhagen 		message->AddInt32("nodeID", ref->id());
647a0795c6fSMarcus Overhagen 		subMenu->AddItem(new BMenuItem(
6482cba2d56SDancsó Róbert 			B_TRANSLATE("Start time source"),
649a0795c6fSMarcus Overhagen 			message));
650a0795c6fSMarcus Overhagen 		message = new BMessage(MediaRoutingView::M_NODE_START_TIME_SOURCE);
651a0795c6fSMarcus Overhagen 		message->AddInt32("nodeID", ref->id());
652a0795c6fSMarcus Overhagen 		subMenu->AddItem(new BMenuItem(
6532cba2d56SDancsó Róbert 			B_TRANSLATE("Stop time source"),
654a0795c6fSMarcus Overhagen 			message));
655a0795c6fSMarcus Overhagen 	}
656a0795c6fSMarcus Overhagen 	// [c.lenz 24dec99] support for BControllable::StartControlPanel()
657a0795c6fSMarcus Overhagen 	if(ref->kind() & B_CONTROLLABLE) {
658a0795c6fSMarcus Overhagen 		if (subMenu->CountItems() > 0)
659a0795c6fSMarcus Overhagen 			subMenu->AddSeparatorItem();
660a0795c6fSMarcus Overhagen 		message = new BMessage(MediaRoutingView::M_NODE_START_CONTROL_PANEL);
6612cba2d56SDancsó Róbert 		subMenu->AddItem(new BMenuItem(B_TRANSLATE("Start control panel"),
6622cba2d56SDancsó Róbert 			message, 'P', B_COMMAND_KEY | B_SHIFT_KEY));
663a0795c6fSMarcus Overhagen 	}
664a0795c6fSMarcus Overhagen 	// [em 1feb00] group tweaks
665a0795c6fSMarcus Overhagen 	if(ref->group())
666a0795c6fSMarcus Overhagen 	{
667a0795c6fSMarcus Overhagen 		message = new BMessage(MediaRoutingView::M_GROUP_SET_LOCKED);
668a0795c6fSMarcus Overhagen 		message->AddInt32("groupID", ref->group()->id());
669a0795c6fSMarcus Overhagen 		bool isLocked = (ref->group()->groupFlags() & NodeGroup::GROUP_LOCKED);
670a0795c6fSMarcus Overhagen 		message->AddBool("locked", !isLocked);
671a0795c6fSMarcus Overhagen 		if (subMenu->CountItems() > 0)
672a0795c6fSMarcus Overhagen 			subMenu->AddSeparatorItem();
673a0795c6fSMarcus Overhagen 		subMenu->AddItem(
674a0795c6fSMarcus Overhagen 			new BMenuItem(
6752cba2d56SDancsó Róbert 				isLocked ? B_TRANSLATE("Unlock group")
6762cba2d56SDancsó Róbert 						 : B_TRANSLATE("Lock group"), message));
677a0795c6fSMarcus Overhagen 	}
678a0795c6fSMarcus Overhagen 
679a0795c6fSMarcus Overhagen 	if (subMenu->CountItems() > 0)
680a0795c6fSMarcus Overhagen 	{
681a0795c6fSMarcus Overhagen 		menu->AddItem(subMenu);
682a0795c6fSMarcus Overhagen 		subMenu->SetTargetForItems(view());
683a0795c6fSMarcus Overhagen 	}
684a0795c6fSMarcus Overhagen 
685a0795c6fSMarcus Overhagen 	menu->SetTargetForItems(view());
686a0795c6fSMarcus Overhagen 	view()->ConvertToScreen(&point);
687a0795c6fSMarcus Overhagen 	point -= BPoint(1.0, 1.0);
688a0795c6fSMarcus Overhagen 	menu->Go(point, true, true, true);
689a0795c6fSMarcus Overhagen }
690a0795c6fSMarcus Overhagen 
691a0795c6fSMarcus Overhagen // ---------------------------------------------------------------- //
692a0795c6fSMarcus Overhagen // BHandler impl
693a0795c6fSMarcus Overhagen // ---------------------------------------------------------------- //
694a0795c6fSMarcus Overhagen 
MessageReceived(BMessage * message)695a0795c6fSMarcus Overhagen void MediaNodePanel::MessageReceived(
696a0795c6fSMarcus Overhagen 	BMessage *message)
697a0795c6fSMarcus Overhagen {
698a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::MessageReceived()\n"));
699a0795c6fSMarcus Overhagen 	switch (message->what)
700a0795c6fSMarcus Overhagen 	{
701a0795c6fSMarcus Overhagen 		case NodeRef::M_INPUTS_CHANGED:
702a0795c6fSMarcus Overhagen 		{
703a0795c6fSMarcus Overhagen 			D_MESSAGE(("MediaNodePanel::MessageReceived(NodeRef::M_INPUTS_CHANGED)\n"));
704a0795c6fSMarcus Overhagen 			_updateIcon(dynamic_cast<MediaRoutingView *>(view())->getLayout());
705a0795c6fSMarcus Overhagen 			break;
706a0795c6fSMarcus Overhagen 		}
707a0795c6fSMarcus Overhagen 		case NodeRef::M_OUTPUTS_CHANGED:
708a0795c6fSMarcus Overhagen 		{
709a0795c6fSMarcus Overhagen 			D_MESSAGE(("MediaNodePanel::MessageReceived(NodeRef::M_OUTPUTS_CHANGED)\n"));
710a0795c6fSMarcus Overhagen 			_updateIcon(dynamic_cast<MediaRoutingView *>(view())->getLayout());
711a0795c6fSMarcus Overhagen 			break;
712a0795c6fSMarcus Overhagen 		}
713a0795c6fSMarcus Overhagen 		default:
714a0795c6fSMarcus Overhagen 		{
715a0795c6fSMarcus Overhagen 			BHandler::MessageReceived(message);
716a0795c6fSMarcus Overhagen 			break;
717a0795c6fSMarcus Overhagen 		}
718a0795c6fSMarcus Overhagen 	}
719a0795c6fSMarcus Overhagen }
720a0795c6fSMarcus Overhagen 
721a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
722a0795c6fSMarcus Overhagen // *** IStateArchivable
723a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
724a0795c6fSMarcus Overhagen 
importState(const BMessage * archive)725a0795c6fSMarcus Overhagen status_t MediaNodePanel::importState(
726a0795c6fSMarcus Overhagen 	const BMessage*						archive) {
727a0795c6fSMarcus Overhagen 
728a0795c6fSMarcus Overhagen 	BPoint iconPos(s_invalidPosition);
729a0795c6fSMarcus Overhagen 	BPoint miniIconPos(s_invalidPosition);
730a0795c6fSMarcus Overhagen 
731a0795c6fSMarcus Overhagen 	MediaRoutingView* v = dynamic_cast<MediaRoutingView*>(view());
732a0795c6fSMarcus Overhagen 	ASSERT(v);
733a0795c6fSMarcus Overhagen 	MediaRoutingView::layout_t layoutMode = v->getLayout();
734a0795c6fSMarcus Overhagen 	archive->FindPoint("iconPos", &iconPos);
735a0795c6fSMarcus Overhagen 	archive->FindPoint("miniIconPos", &miniIconPos);
736a0795c6fSMarcus Overhagen 
737a0795c6fSMarcus Overhagen 	switch(layoutMode) {
738a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_ICON_VIEW:
739a0795c6fSMarcus Overhagen 			if(iconPos != s_invalidPosition)
740a0795c6fSMarcus Overhagen 				moveTo(iconPos);
741a0795c6fSMarcus Overhagen 			m_alternatePosition = miniIconPos;
742a0795c6fSMarcus Overhagen 			break;
743a0795c6fSMarcus Overhagen 
744a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_MINI_ICON_VIEW:
745a0795c6fSMarcus Overhagen 			if(miniIconPos != s_invalidPosition)
746a0795c6fSMarcus Overhagen 				moveTo(miniIconPos);
747a0795c6fSMarcus Overhagen 			m_alternatePosition = iconPos;
748a0795c6fSMarcus Overhagen 			break;
749a0795c6fSMarcus Overhagen 	}
750a0795c6fSMarcus Overhagen 
751a0795c6fSMarcus Overhagen 	return B_OK;
752a0795c6fSMarcus Overhagen }
753a0795c6fSMarcus Overhagen 
exportState(BMessage * archive) const754a0795c6fSMarcus Overhagen status_t MediaNodePanel::exportState(
755a0795c6fSMarcus Overhagen 	BMessage*									archive) const {
756a0795c6fSMarcus Overhagen 
757a0795c6fSMarcus Overhagen 	BPoint iconPos, miniIconPos;
758a0795c6fSMarcus Overhagen 
759a0795c6fSMarcus Overhagen 	MediaRoutingView* v = dynamic_cast<MediaRoutingView*>(view());
760a0795c6fSMarcus Overhagen 	ASSERT(v);
761a0795c6fSMarcus Overhagen 	MediaRoutingView::layout_t layoutMode = v->getLayout();
762a0795c6fSMarcus Overhagen 	switch(layoutMode) {
763a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_ICON_VIEW:
7645680c33eSIngo Weinhold 			iconPos = Frame().LeftTop();
765a0795c6fSMarcus Overhagen 			miniIconPos = m_alternatePosition;
766a0795c6fSMarcus Overhagen 			break;
767a0795c6fSMarcus Overhagen 
768a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_MINI_ICON_VIEW:
7695680c33eSIngo Weinhold 			miniIconPos = Frame().LeftTop();
770a0795c6fSMarcus Overhagen 			iconPos = m_alternatePosition;
771a0795c6fSMarcus Overhagen 			break;
772a0795c6fSMarcus Overhagen 	}
773a0795c6fSMarcus Overhagen 
774a0795c6fSMarcus Overhagen 	if(iconPos != s_invalidPosition)
775a0795c6fSMarcus Overhagen 		archive->AddPoint("iconPos", iconPos);
776a0795c6fSMarcus Overhagen 	if(miniIconPos != s_invalidPosition)
777a0795c6fSMarcus Overhagen 		archive->AddPoint("miniIconPos", miniIconPos);
778a0795c6fSMarcus Overhagen 
779a0795c6fSMarcus Overhagen 	// determine if I'm a 'system' node
780a0795c6fSMarcus Overhagen 	port_info portInfo;
781a0795c6fSMarcus Overhagen 	app_info appInfo;
782a0795c6fSMarcus Overhagen 
783a0795c6fSMarcus Overhagen 	if ((get_port_info(ref->node().port, &portInfo) == B_OK)
784a0795c6fSMarcus Overhagen 		&& (be_roster->GetRunningAppInfo(portInfo.team, &appInfo) == B_OK)) {
785a0795c6fSMarcus Overhagen 		BEntry appEntry(&appInfo.ref);
786a0795c6fSMarcus Overhagen 		char appName[B_FILE_NAME_LENGTH];
787a0795c6fSMarcus Overhagen 		if(
788a0795c6fSMarcus Overhagen 			appEntry.InitCheck() == B_OK &&
789a0795c6fSMarcus Overhagen 			appEntry.GetName(appName) == B_OK &&
790a0795c6fSMarcus Overhagen 			(!strcmp(appName, "media_addon_server") ||
791a0795c6fSMarcus Overhagen 			 !strcmp(appName, "audio_server"))) {
792a0795c6fSMarcus Overhagen 
793a0795c6fSMarcus Overhagen 			archive->AddBool("sysOwned", true);
794a0795c6fSMarcus Overhagen 		}
795a0795c6fSMarcus Overhagen 	}
796a0795c6fSMarcus Overhagen 
797a0795c6fSMarcus Overhagen 	return B_OK;
798a0795c6fSMarcus Overhagen }
799a0795c6fSMarcus Overhagen 
800a0795c6fSMarcus Overhagen // ---------------------------------------------------------------- //
801a0795c6fSMarcus Overhagen // *** internal operations
802a0795c6fSMarcus Overhagen // ---------------------------------------------------------------- //
803a0795c6fSMarcus Overhagen 
_prepareLabel()804a0795c6fSMarcus Overhagen void MediaNodePanel::_prepareLabel()
805a0795c6fSMarcus Overhagen {
806a0795c6fSMarcus Overhagen 	// find out if its a file node first
807a0795c6fSMarcus Overhagen 	if (ref->kind() & B_FILE_INTERFACE)
808a0795c6fSMarcus Overhagen 	{
809a0795c6fSMarcus Overhagen 		entry_ref nodeFile;
810a0795c6fSMarcus Overhagen 		status_t error = BMediaRoster::Roster()->GetRefFor(ref->node(),	&nodeFile);
811a0795c6fSMarcus Overhagen 		if (error)
812a0795c6fSMarcus Overhagen 		{
8132cba2d56SDancsó Róbert 			m_fullLabel = B_TRANSLATE("%refname% (no file)");
8142cba2d56SDancsó Róbert 			m_fullLabel.ReplaceFirst("%refname%", ref->name());
815a0795c6fSMarcus Overhagen 		}
816a0795c6fSMarcus Overhagen 		else
817a0795c6fSMarcus Overhagen 		{
818a0795c6fSMarcus Overhagen 			BEntry entry(&nodeFile);
819a0795c6fSMarcus Overhagen 			char fileName[B_FILE_NAME_LENGTH];
820a0795c6fSMarcus Overhagen 			entry.GetName(fileName);
821a0795c6fSMarcus Overhagen 			m_fullLabel = fileName;
822a0795c6fSMarcus Overhagen 		}
823a0795c6fSMarcus Overhagen 	}
824a0795c6fSMarcus Overhagen 	else
825a0795c6fSMarcus Overhagen 	{
826a0795c6fSMarcus Overhagen 		m_fullLabel = ref->name();
827a0795c6fSMarcus Overhagen 	}
828a0795c6fSMarcus Overhagen 
829a0795c6fSMarcus Overhagen 	int32 layout = dynamic_cast<MediaRoutingView *>(view())->getLayout();
830a0795c6fSMarcus Overhagen 
831a0795c6fSMarcus Overhagen 	// Construct labelRect
832a0795c6fSMarcus Overhagen 	font_height fh;
833a0795c6fSMarcus Overhagen 	be_plain_font->GetHeight(&fh);
834a0795c6fSMarcus Overhagen 	switch (layout)
835a0795c6fSMarcus Overhagen 	{
836a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_ICON_VIEW:
837a0795c6fSMarcus Overhagen 		{
8385680c33eSIngo Weinhold 			m_labelRect = Frame();
839a0795c6fSMarcus Overhagen 			m_labelRect.OffsetTo(0.0, 0.0);
840a0795c6fSMarcus Overhagen 			m_labelRect.bottom = 2 * M_LABEL_V_MARGIN + (fh.ascent + fh.descent + fh.leading) + 1.0;
841a0795c6fSMarcus Overhagen 			break;
842a0795c6fSMarcus Overhagen 		}
843a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_MINI_ICON_VIEW:
844a0795c6fSMarcus Overhagen 		{
8455680c33eSIngo Weinhold 			m_labelRect = Frame();
846a0795c6fSMarcus Overhagen 			m_labelRect.OffsetTo(0.0, 0.0);
847a0795c6fSMarcus Overhagen 			m_labelRect.left = M_BODY_H_MARGIN + B_MINI_ICON;
848a0795c6fSMarcus Overhagen 			m_labelRect.top += MediaJack::M_DEFAULT_HEIGHT;
849a0795c6fSMarcus Overhagen 			m_labelRect.bottom -= MediaJack::M_DEFAULT_HEIGHT;
850a0795c6fSMarcus Overhagen 			break;
851a0795c6fSMarcus Overhagen 		}
852a0795c6fSMarcus Overhagen 	}
853a0795c6fSMarcus Overhagen 
854a0795c6fSMarcus Overhagen 	// truncate the label to fit in the panel
855de6a5cb9SMichael Lotz 	m_label = m_fullLabel;
856a0795c6fSMarcus Overhagen 	float maxWidth = m_labelRect.Width() - (2.0 * M_LABEL_H_MARGIN) - 2.0;
857a0795c6fSMarcus Overhagen 	if (be_plain_font->StringWidth(m_fullLabel.String()) > maxWidth)
858a0795c6fSMarcus Overhagen 	{
859de6a5cb9SMichael Lotz 		be_plain_font->TruncateString(&m_label, B_TRUNCATE_END, maxWidth);
860a0795c6fSMarcus Overhagen 		m_labelTruncated = true;
861a0795c6fSMarcus Overhagen 	}
862a0795c6fSMarcus Overhagen 
863a0795c6fSMarcus Overhagen 	// Construct labelOffset
864a0795c6fSMarcus Overhagen 	float fw = be_plain_font->StringWidth(m_label.String());
865a0795c6fSMarcus Overhagen 	m_labelOffset.x = m_labelRect.left + m_labelRect.Width() / 2.0 - fw / 2.0;
866a0795c6fSMarcus Overhagen 	m_labelOffset.y = m_labelRect.bottom - M_LABEL_V_MARGIN - fh.descent - (fh.leading / 2.0) - 1.0;
867a0795c6fSMarcus Overhagen 
868a0795c6fSMarcus Overhagen 	// Construct bodyRect
869a0795c6fSMarcus Overhagen 	switch (layout)
870a0795c6fSMarcus Overhagen 	{
871a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_ICON_VIEW:
872a0795c6fSMarcus Overhagen 		{
8735680c33eSIngo Weinhold 			m_bodyRect = Frame();
874a0795c6fSMarcus Overhagen 			m_bodyRect.OffsetTo(0.0, 0.0);
875a0795c6fSMarcus Overhagen 			m_bodyRect.top = m_labelRect.bottom;
876a0795c6fSMarcus Overhagen 			break;
877a0795c6fSMarcus Overhagen 		}
878a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_MINI_ICON_VIEW:
879a0795c6fSMarcus Overhagen 		{
8805680c33eSIngo Weinhold 			m_bodyRect = Frame();
881a0795c6fSMarcus Overhagen 			m_bodyRect.OffsetTo(0.0, 0.0);
882a0795c6fSMarcus Overhagen 			m_bodyRect.right = m_labelRect.left;
883a0795c6fSMarcus Overhagen 			break;
884a0795c6fSMarcus Overhagen 		}
885a0795c6fSMarcus Overhagen 	}
886a0795c6fSMarcus Overhagen }
887a0795c6fSMarcus Overhagen 
_updateBitmap()888a0795c6fSMarcus Overhagen void MediaNodePanel::_updateBitmap()
889a0795c6fSMarcus Overhagen {
890a0795c6fSMarcus Overhagen 	if (m_bitmap)
891a0795c6fSMarcus Overhagen 	{
892a0795c6fSMarcus Overhagen 		delete m_bitmap;
893a0795c6fSMarcus Overhagen 	}
894*c377d661SGerasim Troeglazov 	BBitmap *tempBitmap = new BBitmap(Frame().OffsetToCopy(0.0, 0.0),
895*c377d661SGerasim Troeglazov 		B_RGBA32, true);
896a0795c6fSMarcus Overhagen 	tempBitmap->Lock();
897a0795c6fSMarcus Overhagen 	{
898a0795c6fSMarcus Overhagen 		BView *tempView = new BView(tempBitmap->Bounds(), "", B_FOLLOW_NONE, 0);
899a0795c6fSMarcus Overhagen 		tempBitmap->AddChild(tempView);
900a0795c6fSMarcus Overhagen 		tempView->SetOrigin(0.0, 0.0);
901a0795c6fSMarcus Overhagen 
902a0795c6fSMarcus Overhagen 		int32 layout = dynamic_cast<MediaRoutingView *>(view())->getLayout();
903a0795c6fSMarcus Overhagen 		_drawInto(tempView, tempView->Bounds(), layout);
904a0795c6fSMarcus Overhagen 
905a0795c6fSMarcus Overhagen 		tempView->Sync();
906a0795c6fSMarcus Overhagen 		tempBitmap->RemoveChild(tempView);
907a0795c6fSMarcus Overhagen 		delete tempView;
908a0795c6fSMarcus Overhagen 	}
909a0795c6fSMarcus Overhagen 	tempBitmap->Unlock();
910a0795c6fSMarcus Overhagen 	m_bitmap = new BBitmap(tempBitmap);
911a0795c6fSMarcus Overhagen 	delete tempBitmap;
912a0795c6fSMarcus Overhagen }
913a0795c6fSMarcus Overhagen 
_drawInto(BView * target,BRect targetRect,int32 layout)914a0795c6fSMarcus Overhagen void MediaNodePanel::_drawInto(
915a0795c6fSMarcus Overhagen 	BView *target,
916a0795c6fSMarcus Overhagen 	BRect targetRect,
917a0795c6fSMarcus Overhagen 	int32 layout)
918a0795c6fSMarcus Overhagen {
919a0795c6fSMarcus Overhagen 	switch (layout)
920a0795c6fSMarcus Overhagen 	{
921a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_ICON_VIEW:
922a0795c6fSMarcus Overhagen 		{
923a0795c6fSMarcus Overhagen 			BRect r;
924a0795c6fSMarcus Overhagen 			BPoint p;
925a0795c6fSMarcus Overhagen 
926a0795c6fSMarcus Overhagen 			// Draw borders
927a0795c6fSMarcus Overhagen 			r = targetRect;
928a0795c6fSMarcus Overhagen 			target->BeginLineArray(16);
929a0795c6fSMarcus Overhagen 				target->AddLine(r.LeftTop(), r.RightTop(), M_DARK_GRAY_COLOR);
930a0795c6fSMarcus Overhagen 				target->AddLine(r.RightTop(), r.RightBottom(), M_DARK_GRAY_COLOR);
931a0795c6fSMarcus Overhagen 				target->AddLine(r.RightBottom(), r.LeftBottom(), M_DARK_GRAY_COLOR);
932a0795c6fSMarcus Overhagen 				target->AddLine(r.LeftBottom(), r.LeftTop(), M_DARK_GRAY_COLOR);
933a0795c6fSMarcus Overhagen 				r.InsetBy(1.0, 1.0);
934a0795c6fSMarcus Overhagen 				target->AddLine(r.LeftTop(), r.RightTop(), M_LIGHT_GRAY_COLOR);
935a0795c6fSMarcus Overhagen 				target->AddLine(r.RightTop(), r.RightBottom(), M_MED_GRAY_COLOR);
936a0795c6fSMarcus Overhagen 				target->AddLine(r.RightBottom(), r.LeftBottom(), M_MED_GRAY_COLOR);
937a0795c6fSMarcus Overhagen 				target->AddLine(r.LeftBottom(), r.LeftTop(), M_LIGHT_GRAY_COLOR);
938a0795c6fSMarcus Overhagen 			target->EndLineArray();
939a0795c6fSMarcus Overhagen 
940a0795c6fSMarcus Overhagen 			// Fill background
941a0795c6fSMarcus Overhagen 			r.InsetBy(1.0, 1.0);
942a0795c6fSMarcus Overhagen 			target->SetLowColor(M_GRAY_COLOR);
943a0795c6fSMarcus Overhagen 			target->FillRect(r, B_SOLID_LOW);
944a0795c6fSMarcus Overhagen 
945a0795c6fSMarcus Overhagen 			// Draw icon
946a0795c6fSMarcus Overhagen 			if (m_icon)
947a0795c6fSMarcus Overhagen 			{
948a0795c6fSMarcus Overhagen 				p.x = m_bodyRect.left + m_bodyRect.Width() / 2.0 - B_LARGE_ICON / 2.0;
949a0795c6fSMarcus Overhagen 				p.y = m_labelRect.bottom + m_bodyRect.Height() / 2.0 - B_LARGE_ICON / 2.0;
950a0795c6fSMarcus Overhagen 				target->SetDrawingMode(B_OP_OVER);
951a0795c6fSMarcus Overhagen 				target->DrawBitmapAsync(m_icon, p);
952a0795c6fSMarcus Overhagen 			}
953a0795c6fSMarcus Overhagen 
954a0795c6fSMarcus Overhagen 			// Draw label
955a0795c6fSMarcus Overhagen 			if (isSelected())
956a0795c6fSMarcus Overhagen 			{
957a0795c6fSMarcus Overhagen 				r = m_labelRect;
958a0795c6fSMarcus Overhagen 				r.InsetBy(M_LABEL_H_MARGIN, M_LABEL_V_MARGIN);
959a0795c6fSMarcus Overhagen 				target->BeginLineArray(4);
960a0795c6fSMarcus Overhagen 					target->AddLine(r.LeftTop(), r.RightTop(), M_LIGHT_BLUE_COLOR);
961a0795c6fSMarcus Overhagen 					target->AddLine(r.RightTop(), r.RightBottom(), M_LIGHT_BLUE_COLOR);
962a0795c6fSMarcus Overhagen 					target->AddLine(r.RightBottom(), r.LeftBottom(), M_LIGHT_BLUE_COLOR);
963a0795c6fSMarcus Overhagen 					target->AddLine(r.LeftBottom(), r.LeftTop(), M_LIGHT_BLUE_COLOR);
964a0795c6fSMarcus Overhagen 				target->EndLineArray();
965a0795c6fSMarcus Overhagen 				r.InsetBy(1.0, 1.0);
966a0795c6fSMarcus Overhagen 				target->SetHighColor(M_DARK_BLUE_COLOR);
967a0795c6fSMarcus Overhagen 				target->FillRect(r, B_SOLID_HIGH);
968a0795c6fSMarcus Overhagen 			}
969a0795c6fSMarcus Overhagen 			target->SetDrawingMode(B_OP_OVER);
970a0795c6fSMarcus Overhagen 			target->SetHighColor(isSelected() ? M_WHITE_COLOR : M_BLACK_COLOR);
971a0795c6fSMarcus Overhagen 			target->DrawString(m_label.String(), m_labelOffset);
972a0795c6fSMarcus Overhagen 			break;
973a0795c6fSMarcus Overhagen 		}
974a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_MINI_ICON_VIEW:
975a0795c6fSMarcus Overhagen 		{
976a0795c6fSMarcus Overhagen 			BRect r;
977a0795c6fSMarcus Overhagen 			BPoint p;
978a0795c6fSMarcus Overhagen 
979a0795c6fSMarcus Overhagen 			// Draw borders
980a0795c6fSMarcus Overhagen 			r = targetRect;
981a0795c6fSMarcus Overhagen 			target->BeginLineArray(16);
982a0795c6fSMarcus Overhagen 				target->AddLine(r.LeftTop(), r.RightTop(), M_DARK_GRAY_COLOR);
983a0795c6fSMarcus Overhagen 				target->AddLine(r.RightTop(), r.RightBottom(), M_DARK_GRAY_COLOR);
984a0795c6fSMarcus Overhagen 				target->AddLine(r.RightBottom(), r.LeftBottom(), M_DARK_GRAY_COLOR);
985a0795c6fSMarcus Overhagen 				target->AddLine(r.LeftBottom(), r.LeftTop(), M_DARK_GRAY_COLOR);
986a0795c6fSMarcus Overhagen 				r.InsetBy(1.0, 1.0);
987a0795c6fSMarcus Overhagen 				target->AddLine(r.LeftTop(), r.RightTop(), M_LIGHT_GRAY_COLOR);
988a0795c6fSMarcus Overhagen 				target->AddLine(r.RightTop(), r.RightBottom(), M_MED_GRAY_COLOR);
989a0795c6fSMarcus Overhagen 				target->AddLine(r.RightBottom(), r.LeftBottom(), M_MED_GRAY_COLOR);
990a0795c6fSMarcus Overhagen 				target->AddLine(r.LeftBottom(), r.LeftTop(), M_LIGHT_GRAY_COLOR);
991a0795c6fSMarcus Overhagen 			target->EndLineArray();
992a0795c6fSMarcus Overhagen 
993a0795c6fSMarcus Overhagen 			// Fill background
994a0795c6fSMarcus Overhagen 			r.InsetBy(1.0, 1.0);
995a0795c6fSMarcus Overhagen 			target->SetLowColor(M_GRAY_COLOR);
996a0795c6fSMarcus Overhagen 			target->FillRect(r, B_SOLID_LOW);
997a0795c6fSMarcus Overhagen 
998a0795c6fSMarcus Overhagen 			// Draw icon
999a0795c6fSMarcus Overhagen 			if (m_icon)
1000a0795c6fSMarcus Overhagen 			{
1001a0795c6fSMarcus Overhagen 				p.x = m_bodyRect.left + M_BODY_H_MARGIN;
1002a0795c6fSMarcus Overhagen 				p.y = m_bodyRect.top + (m_bodyRect.Height() / 2.0) - (B_MINI_ICON / 2.0);
1003a0795c6fSMarcus Overhagen 				target->SetDrawingMode(B_OP_OVER);
1004a0795c6fSMarcus Overhagen 				target->DrawBitmapAsync(m_icon, p);
1005a0795c6fSMarcus Overhagen 			}
1006a0795c6fSMarcus Overhagen 
1007a0795c6fSMarcus Overhagen 			// Draw label
1008a0795c6fSMarcus Overhagen 			if (isSelected())
1009a0795c6fSMarcus Overhagen 			{
1010a0795c6fSMarcus Overhagen 				r = m_labelRect;
1011a0795c6fSMarcus Overhagen 				r.InsetBy(M_LABEL_H_MARGIN, M_LABEL_V_MARGIN);
1012a0795c6fSMarcus Overhagen 				target->BeginLineArray(4);
1013a0795c6fSMarcus Overhagen 					target->AddLine(r.LeftTop(), r.RightTop(), M_LIGHT_BLUE_COLOR);
1014a0795c6fSMarcus Overhagen 					target->AddLine(r.RightTop(), r.RightBottom(), M_LIGHT_BLUE_COLOR);
1015a0795c6fSMarcus Overhagen 					target->AddLine(r.RightBottom(), r.LeftBottom(), M_LIGHT_BLUE_COLOR);
1016a0795c6fSMarcus Overhagen 					target->AddLine(r.LeftBottom(), r.LeftTop(), M_LIGHT_BLUE_COLOR);
1017a0795c6fSMarcus Overhagen 				target->EndLineArray();
1018a0795c6fSMarcus Overhagen 				r.InsetBy(1.0, 1.0);
1019a0795c6fSMarcus Overhagen 				target->SetHighColor(M_DARK_BLUE_COLOR);
1020a0795c6fSMarcus Overhagen 				target->FillRect(r, B_SOLID_HIGH);
1021a0795c6fSMarcus Overhagen 			}
1022a0795c6fSMarcus Overhagen 			target->SetDrawingMode(B_OP_OVER);
1023a0795c6fSMarcus Overhagen 			target->SetHighColor(isSelected() ? M_WHITE_COLOR : M_BLACK_COLOR);
1024a0795c6fSMarcus Overhagen 			target->DrawString(m_label.String(), m_labelOffset);
1025a0795c6fSMarcus Overhagen 			break;
1026a0795c6fSMarcus Overhagen 		}
1027a0795c6fSMarcus Overhagen 	}
1028a0795c6fSMarcus Overhagen }
1029a0795c6fSMarcus Overhagen 
_updateIcon(int32 layout)1030a0795c6fSMarcus Overhagen void MediaNodePanel::_updateIcon(
1031a0795c6fSMarcus Overhagen 	int32 layout)
1032a0795c6fSMarcus Overhagen {
1033a0795c6fSMarcus Overhagen 	D_METHOD(("MediaNodePanel::_updateIcon()\n"));
1034a0795c6fSMarcus Overhagen 
1035a0795c6fSMarcus Overhagen 	if (m_icon)
1036a0795c6fSMarcus Overhagen 	{
1037a0795c6fSMarcus Overhagen 		delete m_icon;
1038a0795c6fSMarcus Overhagen 		m_icon = 0;
1039a0795c6fSMarcus Overhagen 	}
1040a0795c6fSMarcus Overhagen 	RouteAppNodeManager *manager;
1041a0795c6fSMarcus Overhagen 	manager = dynamic_cast<MediaRoutingView *>(view())->manager;
1042a0795c6fSMarcus Overhagen 	switch (layout)
1043a0795c6fSMarcus Overhagen 	{
1044a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_ICON_VIEW:
1045a0795c6fSMarcus Overhagen 		{
1046a0795c6fSMarcus Overhagen 			const MediaIcon *icon = manager->mediaIconFor(ref->id(), B_LARGE_ICON);
1047a0795c6fSMarcus Overhagen 			m_icon = new BBitmap(dynamic_cast<const BBitmap *>(icon));
1048a0795c6fSMarcus Overhagen 			break;
1049a0795c6fSMarcus Overhagen 		}
1050a0795c6fSMarcus Overhagen 		case MediaRoutingView::M_MINI_ICON_VIEW:
1051a0795c6fSMarcus Overhagen 		{
1052a0795c6fSMarcus Overhagen 			const MediaIcon *icon = manager->mediaIconFor(ref->id(), B_MINI_ICON);
1053a0795c6fSMarcus Overhagen 			m_icon = new BBitmap(dynamic_cast<const BBitmap *>(icon));
1054a0795c6fSMarcus Overhagen 			break;
1055a0795c6fSMarcus Overhagen 		}
1056a0795c6fSMarcus Overhagen 	}
1057a0795c6fSMarcus Overhagen }
1058a0795c6fSMarcus Overhagen 
1059a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
1060a0795c6fSMarcus Overhagen // *** sorting methods (friend)
1061a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
1062a0795c6fSMarcus Overhagen 
compareID(const void * lValue,const void * rValue)1063a0795c6fSMarcus Overhagen int __CORTEX_NAMESPACE__ compareID(
1064a0795c6fSMarcus Overhagen 	const void *lValue,
1065a0795c6fSMarcus Overhagen 	const void *rValue)
1066a0795c6fSMarcus Overhagen {
1067a0795c6fSMarcus Overhagen 	int retValue = 0;
1068a0795c6fSMarcus Overhagen 	const MediaNodePanel *lPanel = *(reinterpret_cast<MediaNodePanel * const*>(reinterpret_cast<void * const*>(lValue)));
1069a0795c6fSMarcus Overhagen 	const MediaNodePanel *rPanel = *(reinterpret_cast<MediaNodePanel * const*>(reinterpret_cast<void * const*>(rValue)));
1070a0795c6fSMarcus Overhagen 	if (lPanel && rPanel)
1071a0795c6fSMarcus Overhagen 	{
1072a0795c6fSMarcus Overhagen 		if (lPanel->ref->id() < rPanel->ref->id())
1073a0795c6fSMarcus Overhagen 		{
1074a0795c6fSMarcus Overhagen 			retValue = -1;
1075a0795c6fSMarcus Overhagen 		}
1076a0795c6fSMarcus Overhagen 		else if (lPanel->ref->id() > rPanel->ref->id())
1077a0795c6fSMarcus Overhagen 		{
1078a0795c6fSMarcus Overhagen 			retValue = 1;
1079a0795c6fSMarcus Overhagen 		}
1080a0795c6fSMarcus Overhagen 	}
1081a0795c6fSMarcus Overhagen 	return retValue;
1082a0795c6fSMarcus Overhagen }
1083a0795c6fSMarcus Overhagen 
1084a0795c6fSMarcus Overhagen // END -- MediaNodePanel.cpp --
1085