xref: /haiku/src/apps/cortex/MediaRoutingView/MediaNodePanel.h (revision 922e7ba1f3228e6f28db69b0ded8f86eb32dea17)
1 // MediaNodePanel.h
2 // c.lenz 9oct99
3 //
4 // HISTORY
5 //   c.lenz		9oct99		Begun
6 
7 #ifndef __MediaNodePanel_H__
8 #define __MediaNodePanel_H__
9 
10 // DiagramView
11 #include "DiagramBox.h"
12 // MediaRoutingView
13 #include "MediaJack.h"
14 
15 // STL
16 #include <vector>
17 // Support Kit
18 #include <String.h>
19 
20 #include "IStateArchivable.h"
21 
22 #include "cortex_defs.h"
23 __BEGIN_CORTEX_NAMESPACE
24 
25 int compareID(const void *lValue, const void *rValue);
26 
27 class MediaIcon;
28 class NodeRef;
29 
30 class MediaNodePanel : public DiagramBox,
31 					   public BHandler,
32 					   public IStateArchivable
33 {
34 	typedef	DiagramBox _inherited;
35 
36 public:					// *** constants
37 
38 	// [e.moon 26oct99] moved definitions to MediaNodePanel.cpp
39 	static float	M_DEFAULT_WIDTH;
40 	static float	M_DEFAULT_HEIGHT;
41 	static float	M_LABEL_H_MARGIN;
42 	static float	M_LABEL_V_MARGIN;
43 	static float	M_BODY_H_MARGIN;
44 	static float	M_BODY_V_MARGIN;
45 
46 public:					// *** accessors
47 
48 	NodeRef* const								ref;
49 
50 public:					// *** ctor/dtor
51 
52 						MediaNodePanel(
53 							BPoint position,
54 							NodeRef *nodeRef);
55 
56 	virtual				~MediaNodePanel();
57 
58 public:					// *** derived from DiagramItem
59 
60 	virtual void		attachedToDiagram();
61 
62 	virtual void		detachedFromDiagram();
63 
64 	virtual void		DrawBox();
65 
66 	virtual void		MouseDown(
67 							BPoint point,
68 							uint32 buttons,
69 							uint32 clicks);
70 
71 	virtual void		MouseOver(
72 							BPoint point,
73 							uint32 transit);
74 
75 	virtual void		MessageDropped(
76 							BPoint point,
77 							BMessage *message);
78 
79 	virtual void		selected();
80 
81 	virtual void		deselected();
82 
83 public:					// *** derived from BHandler
84 
85 	virtual void		MessageReceived(
86 							BMessage *message);
87 
88 public:					// *** updating
89 
90 	// is called by the MediaRoutingView when the layout
91 	// (i.e. icon size, orientation, default sizes) have
92 	// changed
93 	void				layoutChanged(
94 							int32 layout);
95 
96 	// query the NodeManager for all free inputs & outputs
97 	// and add a MediaJack instance for each; (connected
98 	// inputs are added when the connection is reported or
99 	// queried)
100 	void				populateInit();
101 
102 	// completely update the list of free input/output jacks
103 	void				updateIOJacks();
104 
105 	// arrange the MediaJacks in order of their IDs, resize
106 	// the panel if more space is needed
107 	void				arrangeIOJacks();
108 
109 	// display popup-menu at the given point
110 	void				showContextMenu(
111 							BPoint point);
112 
113 public:					// *** sorting methods
114 
115 	// used for sorting the panels by media_node_id
116 	friend int			compareID(
117 							const void *lValue,
118 							const void *rValue);
119 
120 public:					// *** IStateArchivable
121 
122 	status_t importState(
123 		const BMessage*						archive); //nyi
124 
125 	status_t exportState(
126 		BMessage*									archive) const; //nyi
127 
128 private:				// *** internal operations
129 
130 	// fetch node name (shortening as necessary to fit)
131 	// and update label placement
132 	void				_prepareLabel();
133 
134 	// update the offscreen bitmap
135 	void				_updateBitmap();
136 
137 	void				_drawInto(
138 							BView *target,
139 							BRect targetRect,
140 							int32 layout);
141 
142 	void				_updateIcon(
143 							int32 layout);
144 
145 private:				// *** data
146 
147 	// a pointer to the panel's offscreen bitmap
148 	BBitmap			   *m_bitmap;
149 
150 	BBitmap			   *m_icon;
151 
152 	BString				m_label; // truncated
153 
154 	BString				m_fullLabel; // not truncated
155 
156 	bool				m_labelTruncated;
157 
158 	BPoint				m_labelOffset;
159 
160 	BRect				m_labelRect;
161 
162 	BRect				m_bodyRect;
163 
164 	// cached position in the "other" layout
165 	BPoint				m_alternatePosition;
166 
167 	bool				m_mouseOverLabel;
168 
169 	// [e.moon 7dec99]
170 	static const BPoint		s_invalidPosition;
171 };
172 
173 __END_CORTEX_NAMESPACE
174 #endif /* __MediaNodePanel_H__ */
175