Merged with trunk R992.
[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/box.h>
28 #include <gtkmm/frame.h>
29 #include <gtkmm/eventbox.h>
30 #include <gtkmm/table.h>
31 #include <gtkmm/entry.h>
32 #include <gtkmm/label.h>
33
34 #include <ardour/types.h>
35 #include <ardour/region.h>
36
37 #include "prompter.h"
38 #include "axis_view.h"
39 #include "enums.h"
40 #include "editing.h"
41 #include "canvas.h"
42 #include "color.h"
43
44 namespace ARDOUR {
45         class Session;
46         class Region;
47         class Session;
48         class RouteGroup;
49         class Playlist;
50 }
51
52 namespace Gtk {
53         class Menu;
54 }
55
56 class PublicEditor;
57 class RegionSelection;
58 class TimeSelection;
59 class PointSelection;
60 class TimeAxisViewItem;
61 class Selection;
62 class Selectable;
63
64 /** Abstract base class for time-axis views (horizontal editor 'strips')
65  *
66  * This class provides the basic LHS controls and display methods. This should be
67  * extended to create functional time-axis based views.
68  */
69 class TimeAxisView : public virtual AxisView
70 {
71   private:
72         enum NamePackingBits {
73                 NameLabelPacked = 0x1,
74                 NameEntryPacked = 0x2
75         };
76
77   public:
78         enum TrackHeight { 
79                 Largest,
80                 Large,
81                 Larger,
82                 Normal,
83                 Smaller,
84                 Small
85         };
86         
87         static uint32_t hLargest;
88         static uint32_t hLarge;
89         static uint32_t hLarger;
90         static uint32_t hNormal;
91         static uint32_t hSmaller;
92         static uint32_t hSmall;
93
94         static uint32_t height_to_pixels (TrackHeight);
95
96         TimeAxisView(ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* parent, ArdourCanvas::Canvas& canvas);
97         virtual ~TimeAxisView ();
98
99         /* public data: XXX create accessor/mutators for these ?? */
100
101         PublicEditor& editor;
102         
103         TrackHeight height_style; 
104         uint32_t    height;  /* in canvas units */
105         uint32_t    effective_height;  /* in canvas units */
106         double      y_position;
107         int         order;
108         
109         ArdourCanvas::Group *canvas_display;
110         Gtk::VBox           *control_parent;
111
112         /* The Standard LHS Controls */
113         Gtk::Frame    controls_frame;
114         Gtk::HBox     controls_hbox;
115         Gtk::EventBox controls_lhs_pad;
116         Gtk::Table    controls_table;
117         Gtk::EventBox controls_ebox;
118         Gtk::VBox     controls_vbox;
119         Gtk::HBox     name_hbox;
120         Gtk::Frame    name_frame;
121         Gtk::Entry    name_entry;
122         
123         void hide_name_label ();
124         void hide_name_entry ();
125         void show_name_label ();
126         void show_name_entry ();
127
128         /** Display this TrackView as the nth component of the parent box, at y.
129          *
130          * @param y 
131          * @param nth
132          * @param parent the parent component
133          * @return the height of this TrackView
134          */
135         virtual guint32 show_at (double y, int& nth, Gtk::VBox *parent);
136
137         bool touched (double top, double bot);
138
139         /** Hides this TrackView */
140         virtual void hide ();
141         bool hidden() const { return _hidden; }
142
143         virtual void set_selected (bool);
144
145         /**
146          * potential handler for entered events
147          */
148
149         virtual void entered () {}
150         virtual void exited () {}
151
152         virtual void set_height (TrackHeight h);
153         void reset_height();
154
155         /** Steps through the defined heights for this TrackView.
156          * Sets bigger to true to step up in size, set to fals eot step smaller.
157          *
158          * @param bigger true if stepping should increase in size, false otherwise
159          */
160         virtual void step_height (bool bigger);
161
162         virtual ARDOUR::RouteGroup* edit_group() const { return 0; }
163         virtual ARDOUR::Playlist* playlist() const { return 0; }
164
165         virtual void set_samples_per_unit (double);
166         virtual void show_selection (TimeSelection&);
167         virtual void hide_selection ();
168         virtual void reshow_selection (TimeSelection&);
169         virtual void show_timestretch (nframes_t start, nframes_t end);
170         virtual void hide_timestretch ();
171
172         virtual void hide_dependent_views (TimeAxisViewItem&) {}
173         virtual void reveal_dependent_views (TimeAxisViewItem&) {}
174
175         /* editing operations */
176         
177         virtual bool cut_copy_clear (Selection&, Editing::CutCopyOp) { return false; }
178         virtual bool paste (nframes_t, float times, Selection&, size_t nth) { return false; }
179         
180         virtual void set_selected_regionviews (RegionSelection&) {}
181         virtual void set_selected_points (PointSelection&) {}
182
183         virtual boost::shared_ptr<ARDOUR::Region> find_next_region (nframes_t pos, ARDOUR::RegionPoint, int32_t dir) {
184                 return boost::shared_ptr<ARDOUR::Region> ();
185         }
186
187         void order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top);
188
189         virtual void get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results);
190         virtual void get_inverted_selectables (Selection&, list<Selectable *>& results);
191
192         /* state/serialization management */
193
194         void set_parent (TimeAxisView& p);
195         bool has_state () const;
196
197         virtual void set_state (const XMLNode&);
198         virtual XMLNode* get_state_node () { return 0; }
199
200         /* call this on the parent */
201
202         virtual XMLNode* get_child_xml_node (const string & childname) { return 0; }
203
204   protected:
205
206         string controls_base_unselected_name;
207         string controls_base_selected_name;
208
209         bool name_entry_button_press (GdkEventButton *ev);
210         bool name_entry_button_release (GdkEventButton *ev);
211         bool name_entry_key_release (GdkEventKey *ev);
212         void name_entry_activated ();
213         sigc::connection name_entry_key_timeout;
214         bool name_entry_key_timed_out ();
215         guint32 last_name_entry_key_press_event;
216         
217         /* derived classes can override these */
218
219         virtual void name_entry_changed ();
220         virtual bool name_entry_focus_in (GdkEventFocus *ev);
221         virtual bool name_entry_focus_out (GdkEventFocus *ev);
222
223         /** Handle mouse relaese on our LHS control name ebox.
224          * 
225          *@ param ev the event
226          */
227         virtual bool controls_ebox_button_release (GdkEventButton *ev);
228         virtual bool controls_ebox_scroll (GdkEventScroll *ev);
229
230         /** Display the standard LHS control menu at when.
231          *
232          * @param when the popup activation time
233          */
234         virtual void popup_display_menu (guint32 when);
235
236         /** Build the standard LHS control menu.
237          * Subclasses should extend this method to add their own menu options.
238          */
239         virtual void build_display_menu ();
240
241         /** Do whatever needs to be done to dynamically reset the LHS control menu.
242          */
243         virtual bool handle_display_menu_map_event (GdkEventAny *ev) { return false; }
244
245         /** Build the standard LHS control size menu for the default heights options.
246          */
247         virtual void build_size_menu();
248
249         /** Displays the standard LHS controls size menu for the track heights
250          *
251          * @param when the popup activation time
252          */
253         void popup_size_menu(guint32 when);
254
255         /** Handle the size option of our main menu.
256          * 
257          * @param ev the event
258          */
259         gint size_click(GdkEventButton *ev);
260
261         /* The standard LHS Track control popup-menus */
262
263         Gtk::Menu *display_menu;
264         Gtk::Menu *size_menu;
265
266         Gtk::Label    name_label;
267
268         TimeAxisView* parent;
269
270         /** Find the parent with state */
271         TimeAxisView* get_parent_with_state();
272
273         std::vector<TimeAxisView*> children;
274         bool is_child (TimeAxisView*);
275
276         void remove_child (TimeAxisView*);
277         void add_child (TimeAxisView*);
278
279         /* selection display */
280
281         ArdourCanvas::Group      *selection_group;
282
283         list<SelectionRect*> free_selection_rects;
284         list<SelectionRect*> used_selection_rects;
285
286         SelectionRect* get_selection_rect(uint32_t id);
287
288         virtual void selection_click (GdkEventButton*);
289
290         bool _hidden;
291         bool _has_state;
292         NamePackingBits name_packing;
293
294         static void compute_controls_size_info ();
295         static bool need_size_info;
296
297         void set_height_pixels (uint32_t h);
298         void color_handler (ColorID, uint32_t);
299
300 }; /* class TimeAxisView */
301
302 #endif /* __ardour_gtk_time_axis_h__ */
303