enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / time_axis_view_item.cc
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 #include <utility>
21
22 #include "pbd/error.h"
23 #include "pbd/stacktrace.h"
24
25 #include "ardour/types.h"
26 #include "ardour/ardour.h"
27
28 #include "gtkmm2ext/utils.h"
29 #include "gtkmm2ext/gui_thread.h"
30
31 #include "canvas/container.h"
32 #include "canvas/rectangle.h"
33 #include "canvas/debug.h"
34 #include "canvas/text.h"
35 #include "canvas/colors.h"
36
37 #include "ardour/profile.h"
38
39 #include "public_editor.h"
40 #include "time_axis_view_item.h"
41 #include "time_axis_view.h"
42 #include "ui_config.h"
43 #include "utils.h"
44 #include "rgb_macros.h"
45
46 #include "pbd/i18n.h"
47
48 using namespace std;
49 using namespace Editing;
50 using namespace Glib;
51 using namespace PBD;
52 using namespace ARDOUR;
53 using namespace ARDOUR_UI_UTILS;
54 using namespace Gtkmm2ext;
55
56 Pango::FontDescription TimeAxisViewItem::NAME_FONT;
57 const double TimeAxisViewItem::NAME_X_OFFSET = 15.0;
58 const double TimeAxisViewItem::GRAB_HANDLE_TOP = 0.0;
59 const double TimeAxisViewItem::GRAB_HANDLE_WIDTH = 10.0;
60
61 int    TimeAxisViewItem::NAME_HEIGHT;
62 double TimeAxisViewItem::NAME_Y_OFFSET;
63 double TimeAxisViewItem::NAME_HIGHLIGHT_SIZE;
64 double TimeAxisViewItem::NAME_HIGHLIGHT_THRESH;
65
66 void
67 TimeAxisViewItem::set_constant_heights ()
68 {
69         NAME_FONT = Pango::FontDescription (UIConfiguration::instance().get_SmallFont());
70
71         Gtk::Window win;
72         Gtk::Label foo;
73         win.add (foo);
74
75         Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
76         int width = 0;
77         int height = 0;
78
79         layout->set_font_description (NAME_FONT);
80         get_pixel_size (layout, width, height);
81
82         layout = foo.create_pango_layout (X_("H")); /* just the ascender */
83
84         NAME_HEIGHT = height;
85
86         /* Config->get_show_name_highlight) == true:
87                 Y_OFFSET is measured from bottom of the time axis view item.
88            Config->get_show_name_highlight) == false:
89                 Y_OFFSET is measured from the top of the time axis view item.
90         */
91
92         if (UIConfiguration::instance().get_show_name_highlight()) {
93                 NAME_Y_OFFSET = height + 1;
94                 NAME_HIGHLIGHT_SIZE = height + 2;
95         } else {
96                 NAME_Y_OFFSET = 3;
97                 NAME_HIGHLIGHT_SIZE = 0;
98         }
99         NAME_HIGHLIGHT_THRESH = NAME_HIGHLIGHT_SIZE * 3;
100 }
101
102 /**
103  * Construct a new TimeAxisViewItem.
104  *
105  * @param it_name the unique name of this item
106  * @param parent the parent canvas group
107  * @param tv the TimeAxisView we are going to be added to
108  * @param spu samples per unit
109  * @param base_color
110  * @param start the start point of this item
111  * @param duration the duration of this item
112  * @param recording true if this is a recording region view
113  * @param automation true if this is an automation region view
114  */
115 TimeAxisViewItem::TimeAxisViewItem(
116         const string & it_name, ArdourCanvas::Item& parent, TimeAxisView& tv, double spu, uint32_t base_color,
117         framepos_t start, framecnt_t duration, bool recording, bool automation, Visibility vis
118         )
119         : trackview (tv)
120         , frame_position (-1)
121         , item_name (it_name)
122         , selection_frame (0)
123         , _height (1.0)
124         , _recregion (recording)
125         , _automation (automation)
126         , _dragging (false)
127         , _width (0.0)
128 {
129         init (&parent, spu, base_color, start, duration, vis, true, true);
130 }
131
132 TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other)
133         : trackable (other)
134         , Selectable (other)
135         , PBD::ScopedConnectionList()
136         , trackview (other.trackview)
137         , frame_position (-1)
138         , item_name (other.item_name)
139         , selection_frame (0)
140         , _height (1.0)
141         , _recregion (other._recregion)
142         , _automation (other._automation)
143         , _dragging (other._dragging)
144         , _width (0.0)
145 {
146         /* share the other's parent, but still create a new group */
147
148         ArdourCanvas::Item* parent = other.group->parent();
149
150         _selected = other._selected;
151
152         init (parent, other.samples_per_pixel, other.fill_color, other.frame_position,
153               other.item_duration, other.visibility, other.wide_enough_for_name, other.high_enough_for_name);
154 }
155
156 void
157 TimeAxisViewItem::init (ArdourCanvas::Item* parent, double fpp, uint32_t base_color,
158                         framepos_t start, framepos_t duration, Visibility vis,
159                         bool wide, bool high)
160 {
161         group = new ArdourCanvas::Container (parent);
162         CANVAS_DEBUG_NAME (group, string_compose ("TAVI group for %1", get_item_name()));
163
164         fill_color = base_color;
165         fill_color_name = "time axis view item base";
166         samples_per_pixel = fpp;
167         frame_position = start;
168         item_duration = duration;
169         name_connected = false;
170         position_locked = false;
171         max_item_duration = ARDOUR::max_framepos;
172         min_item_duration = 0;
173         visibility = vis;
174         _sensitive = true;
175         name_text_width = 0;
176         last_item_width = 0;
177         wide_enough_for_name = wide;
178         high_enough_for_name = high;
179
180         if (duration == 0) {
181                 warning << "Time Axis Item Duration == 0" << endl;
182         }
183
184         if (visibility & ShowFrame) {
185                 frame = new ArdourCanvas::Rectangle (group,
186                                                      ArdourCanvas::Rect (0.0, 0.0,
187                                                                          trackview.editor().sample_to_pixel(duration),
188                                                                          trackview.current_height()));
189
190                 frame->set_outline_what (ArdourCanvas::Rectangle::What (ArdourCanvas::Rectangle::LEFT|ArdourCanvas::Rectangle::RIGHT));
191                 frame->show ();
192
193                 CANVAS_DEBUG_NAME (frame, string_compose ("frame for %1", get_item_name()));
194
195                 if (_recregion) {
196                         frame->set_outline_color (UIConfiguration::instance().color ("recording rect"));
197                 } else {
198                         frame->set_outline_color (UIConfiguration::instance().color ("time axis frame"));
199                 }
200         }
201
202         if (UIConfiguration::instance().get_show_name_highlight() && (visibility & ShowNameHighlight)) {
203
204                 /* rectangle size will be set in ::manage_name_highlight() */
205                 name_highlight = new ArdourCanvas::Rectangle (group);
206                 CANVAS_DEBUG_NAME (name_highlight, string_compose ("name highlight for %1", get_item_name()));
207                 name_highlight->set_data ("timeaxisviewitem", this);
208                 name_highlight->set_outline_what (ArdourCanvas::Rectangle::TOP);
209                 name_highlight->set_outline_color (RGBA_TO_UINT (0,0,0,255)); // this should use a theme color
210
211         } else {
212                 name_highlight = 0;
213         }
214
215         if (visibility & ShowNameText) {
216                 name_text = new ArdourCanvas::Text (group);
217                 CANVAS_DEBUG_NAME (name_text, string_compose ("name text for %1", get_item_name()));
218                 if (UIConfiguration::instance().get_show_name_highlight()) {
219                         name_text->set_position (ArdourCanvas::Duple (NAME_X_OFFSET, trackview.current_height() - NAME_Y_OFFSET));
220                 } else {
221                         name_text->set_position (ArdourCanvas::Duple (NAME_X_OFFSET, NAME_Y_OFFSET));
222                 }
223                 name_text->set_font_description (NAME_FONT);
224                 name_text->set_ignore_events (true);
225         } else {
226                 name_text = 0;
227         }
228
229         /* create our grab handles used for trimming/duration etc */
230         if (!_recregion && !_automation) {
231                 double top   = TimeAxisViewItem::GRAB_HANDLE_TOP;
232                 double width = TimeAxisViewItem::GRAB_HANDLE_WIDTH;
233
234                 frame_handle_start = new ArdourCanvas::Rectangle (group, ArdourCanvas::Rect (0.0, top, width, trackview.current_height()));
235                 CANVAS_DEBUG_NAME (frame_handle_start, "TAVI frame handle start");
236                 frame_handle_start->set_outline (false);
237                 frame_handle_start->set_fill (false);
238                 frame_handle_start->Event.connect (sigc::bind (sigc::mem_fun (*this, &TimeAxisViewItem::frame_handle_crossing), frame_handle_start));
239
240                 frame_handle_end = new ArdourCanvas::Rectangle (group, ArdourCanvas::Rect (0.0, top, width, trackview.current_height()));
241                 CANVAS_DEBUG_NAME (frame_handle_end, "TAVI frame handle end");
242                 frame_handle_end->set_outline (false);
243                 frame_handle_end->set_fill (false);
244                 frame_handle_end->Event.connect (sigc::bind (sigc::mem_fun (*this, &TimeAxisViewItem::frame_handle_crossing), frame_handle_end));
245         } else {
246                 frame_handle_start = frame_handle_end = 0;
247         }
248
249         //set_color (base_color);
250
251         //set_duration (item_duration, this);
252         //set_position (start, this);
253
254         group->Event.connect (sigc::mem_fun (*this, &TimeAxisViewItem::canvas_group_event));
255         //Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&TimeAxisViewItem::parameter_changed, this, _1), gui_context ());
256         //UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &TimeAxisViewItem::parameter_changed));
257 }
258
259 TimeAxisViewItem::~TimeAxisViewItem()
260 {
261         delete group;
262 }
263
264 bool
265 TimeAxisViewItem::canvas_group_event (GdkEvent* /*ev*/)
266 {
267         return false;
268 }
269
270 /**
271  * Set the position of this item on the timeline.
272  *
273  * @param pos the new position
274  * @param src the identity of the object that initiated the change
275  * @return true on success
276  */
277
278 bool
279 TimeAxisViewItem::set_position(framepos_t pos, void* src, double* delta)
280 {
281         if (position_locked) {
282                 return false;
283         }
284
285         frame_position = pos;
286
287         double new_unit_pos = trackview.editor().sample_to_pixel (pos);
288
289         if (delta) {
290                 (*delta) = new_unit_pos - group->position().x;
291                 if (*delta == 0.0) {
292                         return true;
293                 }
294         } else {
295                 if (new_unit_pos == group->position().x) {
296                         return true;
297                 }
298         }
299
300         group->set_x_position (new_unit_pos);
301         PositionChanged (frame_position, src); /* EMIT_SIGNAL */
302
303         return true;
304 }
305
306 /** @return position of this item on the timeline */
307 framepos_t
308 TimeAxisViewItem::get_position() const
309 {
310         return frame_position;
311 }
312
313 /**
314  * Set the duration of this item.
315  *
316  * @param dur the new duration of this item
317  * @param src the identity of the object that initiated the change
318  * @return true on success
319  */
320
321 bool
322 TimeAxisViewItem::set_duration (framecnt_t dur, void* src)
323 {
324         if ((dur > max_item_duration) || (dur < min_item_duration)) {
325                 warning << string_compose (
326                                 P_("new duration %1 frame is out of bounds for %2", "new duration of %1 frames is out of bounds for %2", dur),
327                                 get_item_name(), dur)
328                         << endmsg;
329                 return false;
330         }
331
332         if (dur == 0) {
333                 group->hide();
334         }
335
336         item_duration = dur;
337
338         double end_pixel = trackview.editor().sample_to_pixel (frame_position + dur);
339         double first_pixel = trackview.editor().sample_to_pixel (frame_position);
340
341         reset_width_dependent_items (end_pixel - first_pixel);
342
343         DurationChanged (dur, src); /* EMIT_SIGNAL */
344         return true;
345 }
346
347 /** @return duration of this item */
348 framepos_t
349 TimeAxisViewItem::get_duration() const
350 {
351         return item_duration;
352 }
353
354 /**
355  * Set the maximum duration that this item can have.
356  *
357  * @param dur the new maximum duration
358  * @param src the identity of the object that initiated the change
359  */
360 void
361 TimeAxisViewItem::set_max_duration(framecnt_t dur, void* src)
362 {
363         max_item_duration = dur;
364         MaxDurationChanged(max_item_duration, src); /* EMIT_SIGNAL */
365 }
366
367 /** @return the maximum duration that this item may have */
368 framecnt_t
369 TimeAxisViewItem::get_max_duration() const
370 {
371         return max_item_duration;
372 }
373
374 /**
375  * Set the minimum duration that this item may have.
376  *
377  * @param the minimum duration that this item may be set to
378  * @param src the identity of the object that initiated the change
379  */
380 void
381 TimeAxisViewItem::set_min_duration(framecnt_t dur, void* src)
382 {
383         min_item_duration = dur;
384         MinDurationChanged(max_item_duration, src); /* EMIT_SIGNAL */
385 }
386
387 /** @return the minimum duration that this item mey have */
388 framecnt_t
389 TimeAxisViewItem::get_min_duration() const
390 {
391         return min_item_duration;
392 }
393
394 /**
395  * Set whether this item is locked to its current position.
396  * Locked items cannot be moved until the item is unlocked again.
397  *
398  * @param yn true to lock this item to its current position
399  * @param src the identity of the object that initiated the change
400  */
401 void
402 TimeAxisViewItem::set_position_locked(bool yn, void* src)
403 {
404         position_locked = yn;
405         set_trim_handle_colors();
406         PositionLockChanged (position_locked, src); /* EMIT_SIGNAL */
407 }
408
409 /** @return true if this item is locked to its current position */
410 bool
411 TimeAxisViewItem::get_position_locked() const
412 {
413         return position_locked;
414 }
415
416 /**
417  * Set whether the maximum duration constraint is active.
418  *
419  * @param active set true to enforce the max duration constraint
420  * @param src the identity of the object that initiated the change
421  */
422 void
423 TimeAxisViewItem::set_max_duration_active (bool active, void* /*src*/)
424 {
425         max_duration_active = active;
426 }
427
428 /** @return true if the maximum duration constraint is active */
429 bool
430 TimeAxisViewItem::get_max_duration_active() const
431 {
432         return max_duration_active;
433 }
434
435 /**
436  * Set whether the minimum duration constraint is active.
437  *
438  * @param active set true to enforce the min duration constraint
439  * @param src the identity of the object that initiated the change
440  */
441
442 void
443 TimeAxisViewItem::set_min_duration_active (bool active, void* /*src*/)
444 {
445         min_duration_active = active;
446 }
447
448 /** @return true if the maximum duration constraint is active */
449 bool
450 TimeAxisViewItem::get_min_duration_active() const
451 {
452         return min_duration_active;
453 }
454
455 /**
456  * Set the name of this item.
457  *
458  * @param new_name the new name of this item
459  * @param src the identity of the object that initiated the change
460  */
461
462 void
463 TimeAxisViewItem::set_item_name(std::string new_name, void* src)
464 {
465         if (new_name != item_name) {
466                 std::string temp_name = item_name;
467                 item_name = new_name;
468                 NameChanged (item_name, temp_name, src); /* EMIT_SIGNAL */
469         }
470 }
471
472 /** @return the name of this item */
473 std::string
474 TimeAxisViewItem::get_item_name() const
475 {
476         return item_name;
477 }
478
479 /**
480  * Set selection status.
481  *
482  * @param yn true if this item is currently selected
483  */
484 void
485 TimeAxisViewItem::set_selected(bool yn)
486 {
487         if (_selected == yn) {
488                 return;
489         }
490
491         Selectable::set_selected (yn);
492         set_frame_color ();
493         set_name_text_color ();
494
495         if (_selected && frame) {
496                 if (!selection_frame) {
497                         selection_frame = new ArdourCanvas::Rectangle (group);
498                         selection_frame->set_fill (false);
499                         selection_frame->set_outline_color (UIConfiguration::instance().color ("selected time axis frame"));
500                         selection_frame->set_ignore_events (true);
501                 }
502                 selection_frame->set (frame->get().shrink (1.0));
503                 selection_frame->show ();
504         } else {
505                 if (selection_frame) {
506                         selection_frame->hide ();
507                 }
508         }
509 }
510
511 /** @return the TimeAxisView that this item is on */
512 TimeAxisView&
513 TimeAxisViewItem::get_time_axis_view () const
514 {
515         return trackview;
516 }
517
518 /**
519  * Set the displayed item text.
520  * This item is the visual text name displayed on the canvas item, this can be different to the name of the item.
521  *
522  * @param new_name the new name text to display
523  */
524
525 void
526 TimeAxisViewItem::set_name_text(const string& new_name)
527 {
528         if (!name_text) {
529                 return;
530         }
531
532         name_text_width = pixel_width (new_name, NAME_FONT) + 2;
533         name_text->set (new_name);
534         manage_name_text ();
535         manage_name_highlight ();
536 }
537
538 /**
539  * Set the height of this item.
540  *
541  * @param h new height
542  */
543 void
544 TimeAxisViewItem::set_height (double height)
545 {
546         _height = height;
547
548         manage_name_highlight ();
549
550         if (visibility & ShowNameText) {
551                 if (UIConfiguration::instance().get_show_name_highlight()) {
552                         name_text->set_y_position (height - NAME_Y_OFFSET);
553                 } else {
554                         name_text->set_y_position (NAME_Y_OFFSET);
555                 }
556         }
557
558         if (frame) {
559
560                 frame->set_y0 (0.0);
561                 frame->set_y1 (height);
562
563                 if (frame_handle_start) {
564                         frame_handle_start->set_y1 (height);
565                         frame_handle_end->set_y1 (height);
566                 }
567
568                 if (selection_frame) {
569                         selection_frame->set (frame->get().shrink (1.0));
570                 }
571         }
572 }
573
574 void
575 TimeAxisViewItem::manage_name_highlight ()
576 {
577         if (!name_highlight) {
578                 return;
579         }
580
581         if (_height < NAME_HIGHLIGHT_THRESH) {
582                 high_enough_for_name = false;
583         } else {
584                 high_enough_for_name = true;
585         }
586
587         if (_width < 2.0) {
588                 wide_enough_for_name = false;
589         } else {
590                 wide_enough_for_name = true;
591         }
592
593         if (name_highlight && wide_enough_for_name && high_enough_for_name) {
594
595                 name_highlight->show();
596                 // name_highlight->set_x_position (1.0);
597                 name_highlight->set (ArdourCanvas::Rect (0.0, (double) _height - NAME_HIGHLIGHT_SIZE,  _width - 2.0, _height));
598
599         } else {
600                 name_highlight->hide();
601         }
602
603         manage_name_text ();
604 }
605
606 void
607 TimeAxisViewItem::set_color (uint32_t base_color)
608 {
609         fill_color = base_color;
610         set_colors ();
611 }
612
613 ArdourCanvas::Item*
614 TimeAxisViewItem::get_canvas_frame()
615 {
616         return frame;
617 }
618
619 ArdourCanvas::Item*
620 TimeAxisViewItem::get_canvas_group()
621 {
622         return group;
623 }
624
625 ArdourCanvas::Item*
626 TimeAxisViewItem::get_name_highlight()
627 {
628         return name_highlight;
629 }
630
631 /**
632  * Convenience method to set the various canvas item colors
633  */
634 void
635 TimeAxisViewItem::set_colors()
636 {
637         set_frame_color ();
638
639         if (name_highlight) {
640                 name_highlight->set_fill_color (fill_color);
641         }
642
643         set_name_text_color ();
644         set_trim_handle_colors();
645 }
646
647 void
648 TimeAxisViewItem::set_name_text_color ()
649 {
650         if (!name_text) {
651                 return;
652         }
653
654
655         uint32_t f;
656
657         if (UIConfiguration::instance().get_show_name_highlight()) {
658                 /* name text will always be on top of name highlight, which
659                    will always use our fill color.
660                 */
661                 f = fill_color;
662         } else {
663                 /* name text will be on top of the item, whose color
664                    may vary depending on various conditions.
665                 */
666                 f = get_fill_color ();
667         }
668
669         name_text->set_color (ArdourCanvas::contrasting_text_color (f));
670 }
671
672 ArdourCanvas::Color
673 TimeAxisViewItem::get_fill_color () const
674 {
675         const std::string mod_name = (_dragging ? "dragging region" : fill_color_name);
676
677         if (_selected) {
678                 return UIConfiguration::instance().color_mod ("selected region base", mod_name);
679         } else if (_recregion) {
680                 return UIConfiguration::instance().color ("recording rect");
681         } else if ((!UIConfiguration::instance().get_show_name_highlight() || high_enough_for_name) &&
682                    !UIConfiguration::instance().get_color_regions_using_track_color()) {
683                 return UIConfiguration::instance().color_mod (fill_color_name, mod_name);
684         }
685         return UIConfiguration::instance().color_mod (fill_color, mod_name);
686 }
687
688 /**
689  * Sets the frame color depending on whether this item is selected
690  */
691 void
692 TimeAxisViewItem::set_frame_color()
693 {
694         if (!frame) {
695                 return;
696         }
697
698         frame->set_fill_color (get_fill_color());
699         set_frame_gradient ();
700
701         if (!_recregion) {
702                 frame->set_outline_color (UIConfiguration::instance().color ("time axis frame"));
703         }
704 }
705
706 void
707 TimeAxisViewItem::set_frame_gradient ()
708 {
709         if (UIConfiguration::instance().get_timeline_item_gradient_depth() == 0.0) {
710                 frame->set_gradient (ArdourCanvas::Fill::StopList (), 0);
711                 return;
712         }
713
714         ArdourCanvas::Fill::StopList stops;
715         double r, g, b, a;
716         double h, s, v;
717         ArdourCanvas::Color f (get_fill_color());
718
719         /* need to get alpha value */
720         ArdourCanvas::color_to_rgba (f, r, g, b, a);
721
722         stops.push_back (std::make_pair (0.0, f));
723
724         /* now a darker version */
725
726         ArdourCanvas::color_to_hsv (f, h, s, v);
727
728         v = min (1.0, v * (1.0 - UIConfiguration::instance().get_timeline_item_gradient_depth()));
729
730         ArdourCanvas::Color darker = ArdourCanvas::hsva_to_color (h, s, v, a);
731         stops.push_back (std::make_pair (1.0, darker));
732
733         frame->set_gradient (stops, true);
734 }
735
736 /**
737  * Set the colors of the start and end trim handle depending on object state
738  */
739 void
740 TimeAxisViewItem::set_trim_handle_colors()
741 {
742 #if 1
743         /* Leave them transparent for now */
744         if (frame_handle_start) {
745                 frame_handle_start->set_fill_color (0x00000000);
746                 frame_handle_end->set_fill_color (0x00000000);
747         }
748 #else
749         if (frame_handle_start) {
750                 if (position_locked) {
751                         frame_handle_start->set_fill_color (UIConfiguration::instance().get_TrimHandleLocked());
752                         frame_handle_end->set_fill_color (UIConfiguration::instance().get_TrimHandleLocked());
753                 } else {
754                         frame_handle_start->set_fill_color (UIConfiguration::instance().get_TrimHandle());
755                         frame_handle_end->set_fill_color (UIConfiguration::instance().get_TrimHandle());
756                 }
757         }
758 #endif
759 }
760
761 bool
762 TimeAxisViewItem::frame_handle_crossing (GdkEvent* ev, ArdourCanvas::Rectangle* item)
763 {
764         switch (ev->type) {
765         case GDK_LEAVE_NOTIFY:
766                 /* always hide the handle whenever we leave, no matter what mode */
767                 item->set_fill (false);
768                 break;
769         case GDK_ENTER_NOTIFY:
770                 if (trackview.editor().effective_mouse_mode() == Editing::MouseObject) {
771                         /* Never set this to be visible in other modes.  Note, however,
772                            that we do need to undo visibility (LEAVE_NOTIFY case above) no
773                            matter what the mode is. */
774                         item->set_fill (true);
775                 }
776                 break;
777         default:
778                 break;
779         }
780         return false;
781 }
782
783 /** @return the frames per pixel */
784 double
785 TimeAxisViewItem::get_samples_per_pixel () const
786 {
787         return samples_per_pixel;
788 }
789
790 /** Set the frames per pixel of this item.
791  *  This item is used to determine the relative visual size and position of this item
792  *  based upon its duration and start value.
793  *
794  *  @param fpp the new frames per pixel
795  */
796 void
797 TimeAxisViewItem::set_samples_per_pixel (double fpp)
798 {
799         samples_per_pixel = fpp;
800         set_position (this->get_position(), this);
801
802         double end_pixel = trackview.editor().sample_to_pixel (frame_position + get_duration());
803         double first_pixel = trackview.editor().sample_to_pixel (frame_position);
804
805         reset_width_dependent_items (end_pixel - first_pixel);
806 }
807
808 void
809 TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
810 {
811         _width = pixel_width;
812
813         manage_name_highlight ();
814         manage_name_text ();
815
816         if (pixel_width < 2.0) {
817
818                 if (frame) {
819                         frame->set_outline (false);
820                         frame->set_x1 (std::max(1.0, pixel_width));
821                 }
822
823                 if (frame_handle_start) {
824                         frame_handle_start->hide();
825                         frame_handle_end->hide();
826                 }
827
828         } else {
829                 if (frame) {
830                         frame->set_outline (true);
831                         /* Note: x0 is always zero - the position is defined by
832                          * the position of the group, not the frame.
833                          */
834                         frame->set_x1 (pixel_width);
835
836                         if (selection_frame) {
837                                 selection_frame->set (frame->get().shrink (1.0));
838                         }
839                 }
840
841                 if (frame_handle_start) {
842                         if (pixel_width < (3 * TimeAxisViewItem::GRAB_HANDLE_WIDTH)) {
843                                 /*
844                                  * there's less than GRAB_HANDLE_WIDTH of the region between
845                                  * the right-hand end of frame_handle_start and the left-hand
846                                  * end of frame_handle_end, so disable the handles
847                                  */
848
849                                 frame_handle_start->hide();
850                                 frame_handle_end->hide();
851                         } else {
852                                 frame_handle_start->show();
853                                 frame_handle_end->set_x0 (pixel_width - (TimeAxisViewItem::GRAB_HANDLE_WIDTH));
854                                 frame_handle_end->set_x1 (pixel_width);
855                                 frame_handle_end->show();
856                         }
857                 }
858         }
859 }
860
861 void
862 TimeAxisViewItem::manage_name_text ()
863 {
864         int visible_name_width;
865
866         if (!name_text) {
867                 return;
868         }
869
870         if (!wide_enough_for_name || !high_enough_for_name) {
871                 name_text->hide ();
872                 return;
873         }
874
875         if (name_text->text().empty()) {
876                 name_text->hide ();
877         }
878
879         visible_name_width = name_text_width;
880
881         if (visible_name_width > _width - NAME_X_OFFSET) {
882                 visible_name_width = _width - NAME_X_OFFSET;
883         }
884
885         if (visible_name_width < 1) {
886                 name_text->hide ();
887         } else {
888                 name_text->clamp_width (visible_name_width);
889                 name_text->show ();
890         }
891 }
892
893 /**
894  * Callback used to remove this time axis item during the gtk idle loop.
895  * This is used to avoid deleting the obejct while inside the remove_this_item
896  * method.
897  *
898  * @param item the TimeAxisViewItem to remove.
899  * @param src the identity of the object that initiated the change.
900  */
901 gint
902 TimeAxisViewItem::idle_remove_this_item(TimeAxisViewItem* item, void* src)
903 {
904         item->ItemRemoved (item->get_item_name(), src); /* EMIT_SIGNAL */
905         delete item;
906         item = 0;
907         return false;
908 }
909
910 void
911 TimeAxisViewItem::set_y (double y)
912 {
913         group->set_y_position (y);
914 }
915
916 void
917 TimeAxisViewItem::parameter_changed (string p)
918 {
919         if (p == "color-regions-using-track-color") {
920                 set_colors ();
921         } else if (p == "timeline-item-gradient-depth") {
922                 set_frame_gradient ();
923         }
924 }
925
926 void
927 TimeAxisViewItem::drag_start ()
928 {
929         _dragging = true;
930         set_frame_color ();
931 }
932
933 void
934 TimeAxisViewItem::drag_end ()
935 {
936         _dragging = false;
937         set_frame_color ();
938 }