reinstate a canvas group where we reparent regions while dragging, so that they are...
[ardour.git] / gtk2_ardour / time_axis_view_item.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 __gtk_ardour_time_axis_view_item_h__
21 #define __gtk_ardour_time_axis_view_item_h__
22
23 #include <string>
24 #include <gdk/gdk.h>
25 #include <gdkmm/color.h>
26 #include <pangomm/fontdescription.h>
27 #include "pbd/signals.h"
28 #include "selectable.h"
29
30 class TimeAxisView;
31
32 namespace ArdourCanvas {
33         class Pixbuf;
34         class Rectangle;
35         class Item;
36         class Group;
37         class Text;
38 }
39
40 using ARDOUR::framepos_t;
41 using ARDOUR::framecnt_t;
42
43 /**
44  * Base class for items that may appear upon a TimeAxisView.
45  */
46
47 class TimeAxisViewItem : public Selectable, public PBD::ScopedConnectionList
48 {
49    public:
50         virtual ~TimeAxisViewItem();
51
52         virtual bool set_position(framepos_t, void*, double* delta = 0);
53         framepos_t get_position() const;
54         virtual bool set_duration(framecnt_t, void*);
55         framecnt_t get_duration() const;
56         virtual void set_max_duration(framecnt_t, void*);
57         framecnt_t get_max_duration() const;
58         virtual void set_min_duration(framecnt_t, void*);
59         framecnt_t get_min_duration() const;
60         virtual void set_position_locked(bool, void*);
61         bool get_position_locked() const;
62         void set_max_duration_active(bool, void*);
63         bool get_max_duration_active() const;
64         void set_min_duration_active(bool, void*);
65         bool get_min_duration_active() const;
66         void set_item_name(std::string, void*);
67         virtual std::string get_item_name() const;
68         virtual void set_selected(bool yn);
69         void set_sensitive (bool yn) { _sensitive = yn; }
70         bool sensitive () const { return _sensitive; }
71         TimeAxisView& get_time_axis_view () const;
72         void set_name_text(const std::string&);
73         virtual void set_height(double h);
74         void set_y (double);
75         void set_color (Gdk::Color const &);
76         void set_name_text_color ();
77
78         uint32_t get_fill_color () const;
79         void visual_raise_to_top ();
80
81         ArdourCanvas::Item* get_canvas_frame();
82         ArdourCanvas::Group* get_canvas_group();
83         ArdourCanvas::Item* get_name_highlight();
84
85         virtual void set_samples_per_pixel (double);
86
87         double get_samples_per_pixel () const;
88
89         virtual void drag_start() { _dragging = true; }
90         virtual void drag_end() { _dragging = false; }
91         bool dragging() const { return _dragging; }
92
93         virtual void raise () { return; }
94         virtual void raise_to_top () { return; }
95         virtual void lower () { return; }
96         virtual void lower_to_bottom () { return; }
97
98         virtual void hide_rect ();
99         virtual void show_rect ();
100
101         /** @return true if the name area should respond to events */
102         bool name_active() const { return name_connected; }
103
104         // Default sizes, font and spacing
105         static Pango::FontDescription NAME_FONT;
106         static void set_constant_heights ();
107         static const double NAME_X_OFFSET;
108         static const double GRAB_HANDLE_TOP;
109         static const double GRAB_HANDLE_WIDTH;
110
111         /* these are not constant, but vary with the pixel size
112            of the font used to display the item name.
113         */
114         static int    NAME_HEIGHT;
115         static double NAME_Y_OFFSET;
116         static double NAME_HIGHLIGHT_SIZE;
117         static double NAME_HIGHLIGHT_THRESH;
118
119         /* if this is 1.0, we move the right boundary
120            of the item frame so that it is 1 pixel
121            after the end of the item. This gives nice
122            effects when splitting items.
123            
124            if this is zero, the right edge coincides
125            with the end of the item, and things don't
126            look so nice. 
127            
128            this exists to allow easy debugging of the
129            two scenarios.
130         */
131         static const double RIGHT_EDGE_SHIFT;
132
133         /**
134          * Emitted when this Group has been removed.
135          * This is different to the CatchDeletion signal in that this signal
136          * is emitted during the deletion of this Time Axis, and not during
137          * the destructor, this allows us to capture the source of the deletion
138          * event
139          */
140
141         sigc::signal<void,std::string,void*> ItemRemoved;
142
143         /** Emitted when the name of this item is changed */
144         sigc::signal<void,std::string,std::string,void*> NameChanged;
145
146         /** Emiited when the position of this item changes */
147         sigc::signal<void,framepos_t,void*> PositionChanged;
148
149         /** Emitted when the position lock of this item is changed */
150         sigc::signal<void,bool,void*> PositionLockChanged;
151
152         /** Emitted when the duration of this item changes */
153         sigc::signal<void,framecnt_t,void*> DurationChanged;
154
155         /** Emitted when the maximum item duration is changed */
156         sigc::signal<void,framecnt_t,void*> MaxDurationChanged;
157
158         /** Emitted when the mionimum item duration is changed */
159         sigc::signal<void,framecnt_t,void*> MinDurationChanged;
160
161         enum Visibility {
162                 ShowFrame = 0x1,
163                 ShowNameHighlight = 0x2,
164                 ShowNameText = 0x4,
165                 ShowHandles = 0x8,
166                 HideFrameLeft = 0x10,
167                 HideFrameRight = 0x20,
168                 HideFrameTB = 0x40,
169                 FullWidthNameHighlight = 0x80
170         };
171
172   protected:
173         TimeAxisViewItem(const std::string &, ArdourCanvas::Group&, TimeAxisView&, double, Gdk::Color const &,
174                          framepos_t, framecnt_t, bool recording = false, bool automation = false, Visibility v = Visibility (0));
175
176         TimeAxisViewItem (const TimeAxisViewItem&);
177
178         void init (ArdourCanvas::Group*, double, Gdk::Color const &, framepos_t, framepos_t, Visibility, bool, bool);
179
180         virtual bool canvas_group_event (GdkEvent*);
181
182         virtual void compute_colors (Gdk::Color const &);
183         virtual void set_colors();
184         virtual void set_frame_color();
185         virtual void set_frame_gradient ();
186         void set_trim_handle_colors();
187
188         virtual void reset_width_dependent_items (double);
189
190         static gint idle_remove_this_item(TimeAxisViewItem*, void*);
191
192         /** time axis that this item is on */
193         TimeAxisView& trackview;
194
195         /** indicates whether this item is locked to its current position */
196         bool position_locked;
197
198         /** position of this item on the timeline */
199         framepos_t frame_position;
200
201         /** duration of this item upon the timeline */
202         framecnt_t item_duration;
203
204         /** maximum duration that this item can have */
205         framecnt_t max_item_duration;
206
207         /** minimum duration that this item can have */
208         framecnt_t min_item_duration;
209
210         /** indicates whether the max duration constraint is active */
211         bool max_duration_active;
212
213         /** indicates whether the min duration constraint is active */
214         bool min_duration_active;
215
216         /** frames per canvas pixel */
217         double samples_per_pixel;
218
219         /** should the item respond to events */
220         bool _sensitive;
221
222         /**
223          * The unique item name of this Item.
224          * Each item upon a time axis must have a unique id.
225          */
226         std::string item_name;
227
228         /** true if the name should respond to events */
229         bool name_connected;
230
231         /** true if a small vestigial rect should be shown when the item gets very narrow */
232         bool show_vestigial;
233
234         uint32_t fill_opacity;
235         uint32_t fill_color;
236         uint32_t frame_color_r;
237         uint32_t frame_color_g;
238         uint32_t frame_color_b;
239         uint32_t selected_frame_color_r;
240         uint32_t selected_frame_color_g;
241         uint32_t selected_frame_color_b;
242
243         uint32_t last_item_width;
244         int name_text_width;
245         bool wide_enough_for_name;
246         bool high_enough_for_name;
247         bool rect_visible;
248
249         ArdourCanvas::Group*      group;
250         ArdourCanvas::Rectangle* vestigial_frame;
251         ArdourCanvas::Rectangle* frame;
252         ArdourCanvas::Text*      name_text;
253         ArdourCanvas::Rectangle* name_highlight;
254
255         /* with these two values, if frame_handle_start == 0 then frame_handle_end will also be 0 */
256         ArdourCanvas::Rectangle* frame_handle_start; ///< `frame' (fade) handle for the start of the item, or 0
257         ArdourCanvas::Rectangle* frame_handle_end; ///< `frame' (fade) handle for the end of the item, or 0
258
259         bool frame_handle_crossing (GdkEvent*, ArdourCanvas::Rectangle*);
260
261         double _height;
262         Visibility visibility;
263         bool _recregion;
264         bool _automation; ///< true if this is an automation region view
265         bool _dragging;
266
267 private:
268         double _width;
269
270         void parameter_changed (std::string);
271         void manage_name_highlight ();
272         void manage_name_text ();
273
274 }; /* class TimeAxisViewItem */
275
276 #endif /* __gtk_ardour_time_axis_view_item_h__ */