vfs: check userland buffers before reading them.
[haiku.git] / src / apps / cortex / MediaRoutingView / MediaRoutingView.h
blobb8b0fc9b479fa20df3dcf885e7eb5c97ea67cf08
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
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.
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.
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.
32 // MediaRoutingView.h
33 // c.lenz 9oct99
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.
40 // NOTES
42 // *** 9oct99: replaced grid-based version
44 // HISTORY
45 // e.moon 6may99: first stab
46 // c.lenz 6oct99: starting change to DiagramView impl
48 #ifndef __MediaRoutingView__H__
49 #define __MediaRoutingView__H__
51 // DiagramView
52 #include "DiagramView.h"
54 // Media Kit
55 #include "MediaDefs.h"
57 #include <Entry.h>
58 #include <List.h>
59 #include <Message.h>
61 #include "IStateArchivable.h"
63 #include "cortex_defs.h"
64 __BEGIN_CORTEX_NAMESPACE
66 // MediaRoutingView
67 class MediaNodePanel;
68 class MediaWire;
69 // NodeManager
70 class RouteAppNodeManager;
71 class NodeGroup;
72 class NodeRef;
73 class Connection;
74 // RouteApp
75 class NodeSetIOContext;
77 class MediaRoutingView :
78 public DiagramView,
79 public IStateArchivable {
80 typedef DiagramView _inherited;
82 public: // *** constants
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;
90 // [e.moon 7dec99] enum now a named type
91 enum layout_t
93 M_ICON_VIEW = 1,
94 M_MINI_ICON_VIEW
97 public: // messages
99 enum message_t {
100 // INBOUND
101 // "layout" int32: M_ICON_VIEW / M_MINI_ICON_VIEW
102 M_LAYOUT_CHANGED,
104 // INBOUND
105 M_CLEANUP_REQUESTED,
107 // INBOUND
108 // release/delete node
109 // "nodeID" [u]int32: node to release
110 M_RELEASE_NODE,
112 // INBOUND
113 M_SELECT_ALL,
115 // INBOUND
116 M_DELETE_SELECTION,
118 // OUTBOUND
119 // describes a selected node (sent to owning window)
120 // "nodeID" int32
121 M_NODE_SELECTED,
123 // OUTBOUND
124 // describes a selected group (sent to owning window)
125 // "groupID" int32
126 M_GROUP_SELECTED,
128 // INBOUND
129 // requests that the currently selected node/group be broadcast
130 // back to the owning window
131 M_BROADCAST_SELECTION,
133 // INBOUND
134 // request to change the selected nodes cycling mode (on/off)
135 // "cycle" bool
136 M_NODE_CHANGE_CYCLING,
138 // INBOUND
139 // request to change the selected nodes run mode
140 // "run_mode" int32
141 M_NODE_CHANGE_RUN_MODE,
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,
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,
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,
163 // INBOUND
164 // open ParameterWindow for selected nodes
165 // [c.lenz 17feb2000]
166 M_NODE_TWEAK_PARAMETERS,
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
176 public: // *** members
178 RouteAppNodeManager* const manager;
180 public: // *** ctor/dtor
182 MediaRoutingView(
183 RouteAppNodeManager *nodeManager,
184 BRect frame,
185 const char *name,
186 uint32 resizeMode = B_FOLLOW_ALL_SIDES);
188 virtual ~MediaRoutingView();
190 public: // *** DiagramView impl
192 virtual void connectionAborted(
193 DiagramEndPoint *fromWhich);
195 virtual void connectionEstablished(
196 DiagramEndPoint *fromWhich,
197 DiagramEndPoint *toWhich);
199 DiagramWire *createWire(
200 DiagramEndPoint *fromWhich,
201 DiagramEndPoint *woWhich);
203 DiagramWire *createWire(
204 DiagramEndPoint *fromWhich);
206 virtual void BackgroundMouseDown(
207 BPoint point,
208 uint32 buttons,
209 uint32 clicks);
211 virtual void MessageDropped(
212 BPoint point,
213 BMessage *message);
215 virtual void SelectionChanged();
217 public: // *** BView impl
219 virtual void AttachedToWindow();
221 virtual void AllAttached();
223 virtual void DetachedFromWindow();
225 virtual void KeyDown(
226 const char *bytes,
227 int32 count);
229 virtual void Pulse();
231 public: // *** BHandler impl
233 virtual void MessageReceived(
234 BMessage *message);
236 public: // *** accessors
238 layout_t getLayout() const
239 { return m_layout; }
241 public: // *** operations
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;
250 public: // *** IStateArchivable
252 status_t importState(
253 const BMessage* archive);
255 status_t exportState(
256 BMessage* archive) const;
258 // [e.moon 8dec99] subset support
259 status_t importStateFor(
260 const NodeSetIOContext* context,
261 const BMessage* archive);
263 status_t exportStateFor(
264 const NodeSetIOContext* context,
265 BMessage* archive) const;
267 protected: // *** operations
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);
274 // aligns the panels on a grid according to their node_kind
275 void cleanUp();
277 // displays a context menu at a given position
278 void showContextMenu(
279 BPoint point);
281 // will currently display a BAlert; this should change sometime
282 // in the future!
283 void showErrorMessage(
284 BString message,
285 status_t error);
287 private: // *** children management
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);
294 // tries to find the panel to a given media node
295 status_t _findPanelFor(
296 media_node_id id,
297 MediaNodePanel **outPanel) const;
299 // removes the panel of a given media node
300 status_t _removePanelFor(
301 media_node_id);
303 // adds a wire represenation of a media kit connection
304 status_t _addWireFor(
305 Connection &connection);
307 // finds the ui rep of a given Connection object
308 status_t _findWireFor(
309 uint32 connectionID,
310 MediaWire **wire) const;
312 // removes the wire
313 status_t _removeWireFor(
314 uint32 connectionID);
316 private: // *** internal methods
318 // iterates through all selected MediaNodePanels and sets the
319 // 'cycling' state for each to cycle
320 void _changeCyclingForSelection(
321 bool cycle);
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);
328 void _openInfoWindowsForSelection();
330 void _openParameterWindowsForSelection();
332 void _startControlPanelsForSelection();
334 // tries to release every node in the current selection, or to
335 // disconnect wires if those were selected
336 void _deleteSelection();
338 void _addShortcuts();
340 void _initLayout();
342 // populates the view with all nodes currently in the NodeManager
343 void _initContent();
345 void _checkDroppedFile(
346 entry_ref *ref,
347 BPoint dropPoint);
349 void _changeBackground(
350 entry_ref *ref);
352 void _changeBackground(
353 rgb_color color);
355 // adjust scroll bar ranges
356 void _adjustScrollBars();
358 void _broadcastSelection() const;
360 // find & remove an entry in m_inactiveNodeState
361 status_t _fetchInactiveNodeState(
362 MediaNodePanel* forPanel,
363 BMessage* outMessage);
365 void _emptyInactiveNodeState();
367 private:
369 // the current layout
370 layout_t m_layout;
372 // current new-group-name index
373 uint32 m_nextGroupNumber;
375 // holds the id of the node instantiated last thru d&d
376 media_node_id m_lastDroppedNode;
378 // the point at which above node was dropped
379 BPoint m_lastDropPoint;
381 // holds a pointer to the currently dragged wire (if any)
382 MediaWire *m_draggedWire;
384 // stores location of the background bitmap (invalid if no
385 // background bitmap has been set.)
386 // [e.moon 1dec99]
387 BEntry m_backgroundBitmapEntry;
389 // state info for currently inactive nodes (cached from importState())
390 BList m_inactiveNodeState;
393 __END_CORTEX_NAMESPACE
394 #endif /* __MediaRoutingView_H__ */