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