86fd6ae67b096f41bce5d499bd77fcd04477d4ea
[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 */
19
20 #ifndef __ardour_gtk_time_axis_h__
21 #define __ardour_gtk_time_axis_h__
22
23 #include <vector>
24 #include <list>
25
26 #include <gtkmm/box.h>
27 #include <gtkmm/frame.h>
28 #include <gtkmm/drawingarea.h>
29 #include <gtkmm/eventbox.h>
30 #include <gtkmm/table.h>
31 #include <gtkmm/entry.h>
32 #include <gtkmm/label.h>
33
34 #include <gtkmm2ext/focus_entry.h>
35
36 #include "pbd/stateful.h"
37 #include "pbd/signals.h"
38
39 #include "ardour/types.h"
40 #include "ardour/region.h"
41 #include "evoral/Parameter.hpp"
42
43 #include "prompter.h"
44 #include "axis_view.h"
45 #include "enums.h"
46 #include "editing.h"
47
48 namespace ARDOUR {
49         class Session;
50         class Region;
51         class Session;
52         class RouteGroup;
53         class Playlist;
54 }
55
56 namespace Gtk {
57         class Menu;
58 }
59
60 namespace ArdourCanvas {
61         class Canvas;
62         class Group;
63         class Item;
64 }
65
66 class PublicEditor;
67 class RegionSelection;
68 class TimeSelection;
69 class PointSelection;
70 class TimeAxisViewItem;
71 class Selection;
72 class Selectable;
73 class RegionView;
74 class GhostRegion;
75 class StreamView;
76 class ArdourDialog;
77
78 /** Abstract base class for time-axis views (horizontal editor 'strips')
79  *
80  * This class provides the basic LHS controls and display methods. This should be
81  * extended to create functional time-axis based views.
82  */
83 class TimeAxisView : public virtual AxisView
84 {
85   private:
86         enum NamePackingBits {
87                 NameLabelPacked = 0x1,
88                 NameEntryPacked = 0x2
89         };
90
91   public:
92
93         TimeAxisView(ARDOUR::Session* sess, PublicEditor& ed, TimeAxisView* parent, ArdourCanvas::Canvas& canvas);
94         virtual ~TimeAxisView ();
95
96         static PBD::Signal1<void,TimeAxisView*> CatchDeletion;
97
98         /** @return index of this TimeAxisView within its parent */
99         int order () const { return _order; }
100
101         /** @return maximum allowable value of order */
102         static int max_order () { return _max_order; }
103
104         virtual void enter_internal_edit_mode () {}
105         virtual void leave_internal_edit_mode () {}
106
107         ArdourCanvas::Group* canvas_display () { return _canvas_display; }
108         ArdourCanvas::Group* canvas_background () { return _canvas_background; }
109         ArdourCanvas::Group* ghost_group () { return _ghost_group; }
110
111         /** @return effective height (taking children into account) in canvas units, or
112             0 if this TimeAxisView has not yet been shown */
113         uint32_t effective_height () const { return _effective_height; }
114
115         /** @return y position, or -1 if hidden */
116         double y_position () const { return _y_position; }
117
118         /** @return our Editor */
119         PublicEditor& editor () const { return _editor; }
120
121         uint32_t current_height() const { return height; }
122
123         void idle_resize (uint32_t);
124
125         virtual guint32 show_at (double y, int& nth, Gtk::VBox *parent);
126         virtual void hide ();
127
128         void clip_to_viewport ();
129
130         bool touched (double top, double bot);
131
132         /** @return true if hidden, otherwise false */
133         bool hidden () const { return _hidden; }
134
135         void set_selected (bool);
136
137         /**
138          * potential handler for entered events
139          */
140
141         virtual void entered () {}
142         virtual void exited () {}
143
144         virtual void set_height (uint32_t h);
145         void set_height_enum (Height, bool apply_to_selection = false);
146         void reset_height();
147
148         virtual void reset_visual_state ();
149
150         std::pair<TimeAxisView*, double> covers_y_position (double);
151
152         virtual void step_height (bool);
153
154         virtual ARDOUR::RouteGroup* route_group() const { return 0; }
155         virtual boost::shared_ptr<ARDOUR::Playlist> playlist() const { return boost::shared_ptr<ARDOUR::Playlist> (); }
156
157         virtual void set_samples_per_pixel (double);
158         virtual void show_selection (TimeSelection&);
159         virtual void hide_selection ();
160         virtual void reshow_selection (TimeSelection&);
161         virtual void show_timestretch (framepos_t start, framepos_t end, int layers, int layer);
162         virtual void hide_timestretch ();
163
164         /* editing operations */
165
166         virtual void cut_copy_clear (Selection&, Editing::CutCopyOp) {}
167         virtual bool paste (ARDOUR::framepos_t, float /*times*/, Selection&, size_t /*nth*/) { return false; }
168
169         virtual void set_selected_regionviews (RegionSelection&) {}
170         virtual void set_selected_points (PointSelection&) {}
171
172         virtual boost::shared_ptr<ARDOUR::Region> find_next_region (framepos_t /*pos*/, ARDOUR::RegionPoint, int32_t /*dir*/) {
173                 return boost::shared_ptr<ARDOUR::Region> ();
174         }
175
176         void order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top);
177
178         virtual void get_selectables (ARDOUR::framepos_t, ARDOUR::framepos_t, double, double, std::list<Selectable*>&);
179         virtual void get_inverted_selectables (Selection&, std::list<Selectable *>& results);
180
181         void add_ghost (RegionView*);
182         void remove_ghost (RegionView*);
183         void erase_ghost (GhostRegion*);
184
185         /** called at load time when first GUI idle occurs. put
186             expensive data loading/redisplay code in here. */
187         virtual void first_idle () {}
188
189         TimeAxisView* get_parent () { return parent; }
190         void set_parent (TimeAxisView& p);
191
192         virtual LayerDisplay layer_display () const { return Overlaid; }
193         virtual StreamView* view () const { return 0; }
194
195         typedef std::vector<boost::shared_ptr<TimeAxisView> > Children;
196         Children get_child_list ();
197
198         SelectionRect* get_selection_rect(uint32_t id);
199         
200         static uint32_t preset_height (Height);
201
202   protected:
203         /* The Standard LHS Controls */
204         Gtk::HBox              controls_hbox;
205         Gtk::Table             controls_table;
206         Gtk::EventBox          controls_ebox;
207         Gtk::VBox              controls_vbox;
208         Gtk::VBox              time_axis_vbox;
209         Gtk::HBox              name_hbox;
210         Gtk::Label             name_label;
211         bool                  _name_editing;
212         uint32_t               height;  /* in canvas units */
213         std::string            controls_base_unselected_name;
214         std::string            controls_base_selected_name;
215         Gtk::Menu*             display_menu; /* The standard LHS Track control popup-menus */
216         TimeAxisView*          parent;
217         ArdourCanvas::Group*   selection_group;
218         std::list<GhostRegion*> ghosts;
219         std::list<SelectionRect*> free_selection_rects;
220         std::list<SelectionRect*> used_selection_rects;
221         bool                  _hidden;
222         bool                   in_destructor;
223         Gtk::Menu*            _size_menu;
224         ArdourCanvas::Group*  _canvas_display;
225         double                _y_position;
226         PublicEditor&         _editor;
227
228         virtual bool can_edit_name() const;
229
230         bool name_entry_key_release (GdkEventKey *ev);
231         bool name_entry_key_press (GdkEventKey *ev);
232         bool name_entry_focus_out (GdkEventFocus *ev);
233
234         Gtk::Entry* name_entry;
235         void begin_name_edit ();
236         void end_name_edit (int);
237
238         /* derived classes can override these */
239
240         virtual void name_entry_changed ();
241
242         /** Handle mouse relaese on our LHS control name ebox.
243          *
244          *@ param ev the event
245          */
246         virtual bool controls_ebox_button_release (GdkEventButton*);
247         virtual bool controls_ebox_scroll (GdkEventScroll*);
248         virtual bool controls_ebox_button_press (GdkEventButton*);
249         virtual bool controls_ebox_motion (GdkEventMotion*);
250         virtual bool controls_ebox_leave (GdkEventCrossing*);
251
252         /** Display the standard LHS control menu at when.
253          *
254          * @param when the popup activation time
255          */
256         virtual void popup_display_menu (guint32 when);
257
258         /** Build the standard LHS control menu.
259          * Subclasses should extend this method to add their own menu options.
260          */
261         virtual void build_display_menu ();
262
263         /** Do whatever needs to be done to dynamically reset the LHS control menu.
264          */
265         virtual bool handle_display_menu_map_event (GdkEventAny * /*ev*/) { return false; }
266
267         Children children;
268         bool is_child (TimeAxisView*);
269
270         virtual void remove_child (boost::shared_ptr<TimeAxisView>);
271         void add_child (boost::shared_ptr<TimeAxisView>);
272
273         /* selection display */
274
275         virtual void selection_click (GdkEventButton*);
276
277         void color_handler ();
278
279         void conditionally_add_to_selection ();
280
281         void build_size_menu ();
282
283 private:
284         ArdourCanvas::Group* _canvas_background;
285         Gtk::VBox*            control_parent;
286         int                  _order;
287         uint32_t             _effective_height;
288         double               _resize_drag_start;
289         GdkCursor*           _preresize_cursor;
290         bool                 _have_preresize_cursor;
291         ArdourCanvas::Group* _ghost_group;
292         bool                  _ebox_release_can_act;
293
294         static uint32_t button_height;
295         static uint32_t extra_height;
296         static int const _max_order;
297         
298         void compute_heights ();
299         bool maybe_set_cursor (int y);
300
301 }; /* class TimeAxisView */
302
303 #endif /* __ardour_gtk_time_axis_h__ */
304