some C++-ification of GnomeCanvasBlah
[ardour.git] / gtk2_ardour / time_axis_view.h
1 /*
2     Copyright (C) 2003 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #ifndef __ardour_gtk_time_axis_h__
22 #define __ardour_gtk_time_axis_h__
23
24 #include <vector>
25 #include <list>
26
27 #include <gtkmm.h>
28 #include <libgnomecanvasmm/group.h>
29 #include <libgnomecanvasmm/canvas.h>
30
31 #include <ardour/types.h>
32 #include <ardour/region.h>
33
34 #include "prompter.h"
35 #include "axis_view.h"
36 #include "enums.h"
37 #include "editing.h"
38
39 namespace ARDOUR {
40         class Session;
41         class Region;
42         class Session;
43         class RouteGroup;
44         class Playlist;
45 }
46
47 class PublicEditor;
48 class AudioRegionSelection;
49 class TimeSelection;
50 class PointSelection;
51 class TimeAxisViewItem;
52 class Selection;
53 class Selectable;
54
55 /**
56  * TimeAxisView defines the abstract base class for time-axis views.
57  *
58  * This class provides the basic LHS controls and display methods. This should be
59  * extended to create functional time-axis based views.
60  *
61  */
62 class TimeAxisView : public virtual AxisView
63 {
64   public:
65         enum TrackHeight { 
66                 /* canvas units. they need to be odd
67                    valued so that there is a precise
68                    middle.
69                 */
70                 Largest = 301,
71                 Large = 201,
72                 Larger = 101,
73                 Normal = 51,
74                 Smaller = 31,
75                 Small = 21
76         };
77
78         TimeAxisView(ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* parent, Gtk::Widget *canvas);
79         virtual ~TimeAxisView ();
80
81         /* public data: XXX create accessor/mutators for these ?? */
82
83         PublicEditor& editor;
84
85         guint32 height;  /* in canvas units */
86         guint32 effective_height;  /* in canvas units */
87         double  y_position;
88         int     order;
89
90         
91         Gnome::Canvas::Item   *canvas_display;
92         Gtk::VBox       *control_parent;
93
94         /* The Standard LHS Controls */
95         Gtk::Frame    controls_frame;
96         Gtk::HBox     controls_hbox;
97         Gtk::EventBox controls_lhs_pad;
98         Gtk::Table    controls_table;
99         Gtk::EventBox controls_ebox;
100         Gtk::VBox     controls_vbox;
101         Gtk::HBox     name_hbox;
102         Gtk::Frame    name_frame;
103         Gtk::Entry    name_entry;
104
105         /**
106          * Display this TrackView as the nth component of the parent box, at y.
107          *
108          * @param y 
109          * @param nth
110          * @param parent the parent component
111          * @return the height of this TrackView
112          */
113         virtual guint32 show_at (double y, int& nth, Gtk::VBox *parent);
114
115         bool touched (double top, double bot);
116
117         /**
118          * Hides this TrackView
119          */
120         virtual void hide ();
121         bool hidden() const { return _hidden; }
122
123         virtual void set_selected (bool);
124
125         /**
126          * potential handler for entered events
127          */
128
129         virtual void entered () {}
130         virtual void exited () {}
131
132         /**
133          * Sets the height of this TrackView to one of ths TrackHeghts
134          *
135          * @param h the TrackHeight value to set
136          */
137         virtual void set_height (TrackHeight h);
138         void reset_height();
139         /**
140          * Steps through the defined TrackHeights for this TrackView.
141          * Sets bigger to true to step up in size, set to fals eot step smaller.
142          *
143          * @param bigger true if stepping should increase in size, false otherwise
144          */
145         virtual void step_height (bool bigger);
146
147         virtual ARDOUR::RouteGroup* edit_group() const { return 0; }
148         virtual ARDOUR::Playlist* playlist() const { return 0; }
149
150         virtual void set_samples_per_unit (double);
151         virtual void show_selection (TimeSelection&);
152         virtual void hide_selection ();
153         virtual void reshow_selection (TimeSelection&);
154         virtual void show_timestretch (jack_nframes_t start, jack_nframes_t end);
155         virtual void hide_timestretch ();
156
157         virtual void hide_dependent_views (TimeAxisViewItem&) {}
158         virtual void reveal_dependent_views (TimeAxisViewItem&) {}
159
160         /* editing operations */
161         
162         virtual bool cut_copy_clear (Selection&, Editing::CutCopyOp) { return false; }
163         virtual bool paste (jack_nframes_t, float times, Selection&, size_t nth) { return false; }
164         
165         virtual void set_selected_regionviews (AudioRegionSelection&) {}
166         virtual void set_selected_points (PointSelection&) {}
167
168         virtual ARDOUR::Region* find_next_region (jack_nframes_t pos, ARDOUR::RegionPoint, int32_t dir) {
169                 return 0;
170         }
171
172         void order_selection_trims (Gnome::Canvas::Item *item, bool put_start_on_top);
173
174         virtual void get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& results);
175         virtual void get_inverted_selectables (Selection&, list<Selectable *>& results);
176
177         /* state/serialization management */
178
179         void set_parent (TimeAxisView& p);
180         bool has_state () const;
181
182         virtual void set_state (const XMLNode&);
183         virtual XMLNode* get_state_node () { return 0; }
184
185         /* call this on the parent */
186
187         virtual XMLNode* get_child_xml_node (std::string childname) { return 0; }
188
189   protected:
190
191         string controls_base_unselected_name;
192         string controls_base_selected_name;
193
194         /**
195          * Handle mouse press on our LHS control name entry.
196          *
197          * @param ev the event
198          */
199         virtual bool name_entry_button_press (GdkEventButton *ev);
200
201         /**
202          * Handle mouse relaese on our LHS control name entry.
203          * 
204          *@ param ev the event
205          */
206         virtual bool name_entry_button_release (GdkEventButton *ev);
207
208         /**
209          * Handle mouse relaese on our LHS control name ebox.
210          * 
211          *@ param ev the event
212          */
213         virtual gint controls_ebox_button_release (GdkEventButton *ev);
214
215         /**
216          * Displays the standard LHS control menu at when.
217          *
218          * @param when the popup activation time
219          */
220         virtual void popup_display_menu (guint32 when);
221
222         /**
223          * Build the standard LHS control menu.
224          * Subclasses should extend this method to add their own menu options.
225          *
226          */
227         virtual void build_display_menu ();
228
229         /**
230          * Do anything that needs to be done to dynamically reset
231          * the LHS control menu.
232          */
233         virtual gint handle_display_menu_map_event (GdkEventAny *ev) { return FALSE; }
234
235         /**
236          * Build the standard LHS control size menu for the default TrackHeight options.
237          *
238          */
239         virtual void build_size_menu();
240
241         /**
242          * Displays the standard LHS controls size menu for the TrackHeight.
243          *
244          * @parem when the popup activation time
245          */
246         void popup_size_menu(guint32 when);
247
248         /**
249          * Handle the size option of out main menu.
250          * 
251          * @param ev the event
252          */
253         gint size_click(GdkEventButton *ev);
254
255         /* The standard LHS Track control popup-menus */
256
257         Gtk::Menu *display_menu;
258         Gtk::Menu *size_menu;
259
260         Gtk::Label    name_label;
261
262         TimeAxisView* parent;
263
264         /* find the parent with state */
265
266         TimeAxisView* get_parent_with_state();
267
268         std::vector<TimeAxisView*> children;
269         bool is_child (TimeAxisView*);
270
271         void remove_child (TimeAxisView*);
272         void add_child (TimeAxisView*);
273
274         /* selection display */
275
276         Gnome::Canvas::Group      *selection_group;
277
278         list<SelectionRect*> free_selection_rects;
279         list<SelectionRect*> used_selection_rects;
280
281         SelectionRect* get_selection_rect(uint32_t id);
282
283         virtual void selection_click (GdkEventButton*);
284
285         bool _hidden;
286         bool _has_state;
287
288 }; /* class TimeAxisView */
289
290 #endif /* __ardour_gtk_time_axis_h__ */
291