Switched to use libgnomecanvas (not the C++ one).
[ardour.git] / gtk2_ardour / time_axis_view.cc
1 /*
2     Copyright (C) 2000 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 #include <cstdlib>
22 #include <cmath>
23 #include <algorithm>
24 #include <string>
25 #include <list>
26
27 #include <pbd/error.h>
28
29 #include <gtkmm2ext/utils.h>
30 #include <gtkmm2ext/selector.h>
31 #include <gtkmm2ext/stop_signal.h>
32
33 #include <ardour/session.h>
34 #include <ardour/utils.h>
35 #include <ardour/ladspa_plugin.h>
36 #include <ardour/insert.h>
37 #include <ardour/location.h>
38
39 #include "ardour_ui.h"
40 #include "public_editor.h"
41 #include "time_axis_view.h"
42 #include "canvas-simplerect.h"
43 #include "selection.h"
44 #include "keyboard.h"
45 #include "rgb_macros.h"
46
47 #include "i18n.h"
48
49 using namespace Gtk;
50 using namespace sigc;
51 using namespace ARDOUR;
52 using namespace Editing;
53
54 const double trim_handle_size = 6.0; /* pixels */
55
56 TimeAxisView::TimeAxisView(ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* rent, Gtk::Widget *canvas) 
57         : AxisView(sess), 
58           editor(ed),
59           controls_table (2, 9)
60 {
61         canvas_display = gnome_canvas_item_new (gnome_canvas_root(GNOME_CANVAS(canvas->gobj())),
62                                               gnome_canvas_group_get_type(),
63                                               "x", 0.0,
64                                               "y", 0.0,
65                                               NULL);
66
67         selection_group = gnome_canvas_item_new (GNOME_CANVAS_GROUP(canvas_display), 
68                                                gnome_canvas_group_get_type (), 
69                                                NULL);
70         gnome_canvas_item_hide (selection_group);
71         
72         control_parent = 0;
73         display_menu = 0;
74         size_menu = 0;
75         _marked_for_display = false;
76         _hidden = false;
77         height = 0;
78         effective_height = 0;
79         parent = rent;
80         _has_state = false;
81
82         /*
83           Create the standard LHS Controls
84           We create the top-level container and name add the name label here,
85           subclasses can add to the layout as required
86         */
87
88         name_entry.set_name ("EditorTrackNameDisplay");
89         name_entry.button_release_event.connect (mem_fun (*this, &TimeAxisView::name_entry_button_release));
90         name_entry.button_press_event.connect (mem_fun (*this, &TimeAxisView::name_entry_button_press));
91         
92         name_entry.signal_focus_in_event().connect (ptr_fun (ARDOUR_UI::generic_focus_in_event));
93         name_entry.signal_focus_out_event().connect (ptr_fun (ARDOUR_UI::generic_focus_out_event));
94
95         Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name
96
97         name_label.set_name ("TrackLabel");
98         name_label.set_alignment (0.0, 0.5);
99
100         // name_hbox.set_border_width (2);
101         // name_hbox.set_spacing (5);
102
103         /* typically, either name_label OR name_entry are visible,
104            but not both. its up to derived classes to show/hide them as they
105            wish.
106         */
107
108         name_hbox.pack_start (name_label, true, true);
109         name_hbox.pack_start (name_entry, true, true);
110         name_hbox.show ();
111
112         controls_table.set_border_width (2);
113         controls_table.set_row_spacings (0);
114         controls_table.set_col_spacings (0);
115         controls_table.set_homogeneous (true);
116         controls_table.show ();
117
118         controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
119
120         controls_table.show ();
121
122         controls_vbox.pack_start (controls_table, false, false);
123         controls_vbox.show ();
124
125         controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
126         controls_ebox.add (controls_vbox);
127         controls_ebox.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
128         controls_ebox.set_flags (Gtk::CAN_FOCUS);
129
130         controls_ebox.button_release_event.connect (mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
131         
132         controls_lhs_pad.set_name ("TimeAxisViewControlsPadding");
133         controls_hbox.pack_start (controls_lhs_pad,false,false);
134         controls_hbox.pack_start (controls_ebox,true,true);
135         controls_hbox.show ();
136
137         controls_frame.add (controls_hbox);
138         controls_frame.set_name ("TimeAxisViewControlsBaseUnselected");
139         controls_frame.set_shadow_type (Gtk::SHADOW_OUT);
140 }
141
142 TimeAxisView::~TimeAxisView()
143 {
144         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
145                 delete *i;
146         }
147
148         for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
149                 gtk_object_destroy (GTK_OBJECT((*i)->rect));
150                 gtk_object_destroy (GTK_OBJECT((*i)->start_trim));
151                 gtk_object_destroy (GTK_OBJECT((*i)->end_trim));
152         }
153
154         for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
155                 gtk_object_destroy (GTK_OBJECT((*i)->rect));
156                 gtk_object_destroy (GTK_OBJECT((*i)->start_trim));
157                 gtk_object_destroy (GTK_OBJECT((*i)->end_trim));
158         }
159
160         if (selection_group) {
161                 gtk_object_destroy (GTK_OBJECT (selection_group));
162                 selection_group = 0;
163         }
164
165         if (canvas_display) {
166                 gtk_object_destroy (GTK_OBJECT (canvas_display));       
167                 canvas_display = 0;
168         }
169
170         if (display_menu) {
171                 delete display_menu;
172                 display_menu = 0;
173         }
174
175         if (size_menu) {
176                 delete size_menu;
177                 size_menu = 0;
178         }
179 }
180
181 guint32
182 TimeAxisView::show_at (double y, int& nth, VBox *parent)
183 {
184         gdouble ix1, ix2, iy1, iy2;
185         effective_height = 0;
186
187         if (control_parent) {
188                 control_parent->reorder_child (controls_frame, nth);
189         } else {
190                 control_parent = parent;
191                 parent->pack_start (controls_frame, false, false);
192                 parent->reorder_child (controls_frame, nth);
193         }
194
195         controls_frame.show ();
196         controls_ebox.show ();
197
198         /* the coordinates used here are in the system of the
199            item's parent ...
200         */
201
202         gnome_canvas_item_get_bounds (canvas_display, &ix1, &iy1, &ix2, &iy2);
203         gnome_canvas_item_i2w (canvas_display->parent, &ix1, &iy1);
204         if (iy1 < 0) {
205                 iy1 = 0;
206         }
207         gnome_canvas_item_move (canvas_display, 0.0, y - iy1);
208         gnome_canvas_item_show (canvas_display); /* XXX not necessary */
209
210         y_position = y;
211         order = nth;
212         _hidden = false;
213         
214         effective_height = height;
215
216         /* now show children */
217         
218         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
219                 
220                 if ((*i)->marked_for_display()) {
221                         gnome_canvas_item_show ((*i)->canvas_display);
222                 }
223                 
224                 if (GTK_OBJECT_FLAGS(GTK_OBJECT((*i)->canvas_display)) & GNOME_CANVAS_ITEM_VISIBLE) {
225                         ++nth;
226                         effective_height += (*i)->show_at (y + effective_height, nth, parent);
227                 }
228         }
229
230         return effective_height;
231 }
232
233 gint
234 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
235 {
236         switch (ev->button) {
237         case 1:
238                 selection_click (ev);
239                 break;
240
241         case 3:
242                 popup_display_menu (ev->time);
243                 break;
244
245         case 4:
246                 if (Keyboard::no_modifier_keys_pressed (ev)) {
247                         editor.scroll_tracks_up_line ();
248                 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
249                         step_height (true);
250                 }
251                 break;
252
253         case 5:
254                 if (Keyboard::no_modifier_keys_pressed (ev)) {
255                         editor.scroll_tracks_down_line ();
256                 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
257                         step_height (false);
258                 }
259                 break;
260                 
261
262         }
263
264         return TRUE;
265 }
266
267 void
268 TimeAxisView::selection_click (GdkEventButton* ev)
269 {
270         if (Keyboard::modifier_state_contains (ev->state, Keyboard::Shift)) {
271
272                 if (editor.get_selection().selected (this)) {
273                         editor.get_selection().remove (this);
274                 } else {
275                         editor.get_selection().add (this);
276                 }
277
278         } else {
279
280                 editor.get_selection().set (this);
281         }
282 }
283
284 void
285 TimeAxisView::hide ()
286 {
287         if (_hidden) {
288                 return;
289         }
290
291         gnome_canvas_item_hide (canvas_display);
292         controls_frame.hide ();
293
294         if (control_parent) {
295                 control_parent->remove (controls_frame);
296                 control_parent = 0;
297         }
298
299         y_position = -1;
300         _hidden = true;
301         
302         /* now hide children */
303         
304         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
305                 (*i)->hide ();
306         }
307         
308         Hiding ();
309 }
310
311 void
312 TimeAxisView::step_height (bool bigger)
313 {
314         switch (height) {
315         case Largest:
316                 if (!bigger) set_height (Large);
317                 break;
318         case Large:
319                 if (bigger) set_height (Largest);
320                 else set_height (Larger);
321                 break;
322         case Larger:
323                 if (bigger) set_height (Large);
324                 else set_height (Normal);
325                 break;
326         case Normal:
327                 if (bigger) set_height (Larger);
328                 else set_height (Smaller);
329                 break;
330         case Smaller:
331                 if (bigger) set_height (Normal);
332                 else set_height (Small);
333                 break;
334         case Small:
335                 if (bigger) set_height (Smaller);
336                 break;
337         }
338 }
339
340
341 void
342 TimeAxisView::set_height (TrackHeight h)
343 {
344         height = (guint32) h;
345         controls_frame.set_size_request (-1, height);
346
347         if (GTK_OBJECT_FLAGS(GTK_OBJECT(selection_group)) & GNOME_CANVAS_ITEM_VISIBLE) {
348                 /* resize the selection rect */
349                 show_selection (editor.get_selection().time);
350         }
351
352 //      for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
353 //              (*i)->set_height (h);
354 //      }
355
356 }
357
358
359 gint
360 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
361 {
362         if (ev->button == 3) {
363                 return do_not_propagate (ev);
364         }
365         return FALSE;
366 }
367
368 gint
369 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
370 {
371         if (ev->button == 3) {
372                 popup_display_menu (ev->time);
373                 return stop_signal (name_entry, "button_release_event");
374         }
375         return FALSE;
376 }
377
378 void
379 TimeAxisView::popup_display_menu (guint32 when)
380 {
381         if (display_menu == 0) {
382                 build_display_menu ();
383         }
384         display_menu->popup (1, when);  
385 }
386
387 gint
388 TimeAxisView::size_click (GdkEventButton *ev)
389 {
390         popup_size_menu (ev->time);
391         return TRUE;
392 }
393
394 void
395 TimeAxisView::popup_size_menu (guint32 when)
396 {
397         if (size_menu == 0) {
398                 build_size_menu ();
399         }
400         size_menu->popup (1, when);
401 }
402
403 void
404 TimeAxisView::set_selected (bool yn)
405 {
406         AxisView::set_selected (yn);
407
408         if (_selected) {
409                 controls_ebox.set_name (controls_base_selected_name);
410                 controls_frame.set_name (controls_base_selected_name);
411
412                 /* propagate any existing selection, if the mode is right */
413
414                 if (editor.current_mouse_mode() == Editing::MouseRange && !editor.get_selection().time.empty()) {
415                         show_selection (editor.get_selection().time);
416                 }
417
418         } else {
419                 controls_ebox.set_name (controls_base_unselected_name);
420                 controls_frame.set_name (controls_base_unselected_name);
421
422                 hide_selection ();
423
424                 /* children will be set for the yn=true case. but when deselecting
425                    the editor only has a list of top-level trackviews, so we
426                    have to do this here.
427                 */
428
429                 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
430                         (*i)->set_selected (false);
431                 }
432
433                 
434         }
435 }
436
437 void
438 TimeAxisView::build_size_menu ()
439 {
440         using namespace Menu_Helpers;
441
442         size_menu = new Menu;
443         size_menu->set_name ("ArdourContextMenu");
444         MenuList& items = size_menu->items();
445         
446         items.push_back (MenuElem (_("Largest"), bind (mem_fun (*this, &TimeAxisView::set_height), Largest)));
447         items.push_back (MenuElem (_("Large"), bind (mem_fun (*this, &TimeAxisView::set_height), Large)));
448         items.push_back (MenuElem (_("Larger"), bind (mem_fun (*this, &TimeAxisView::set_height), Larger)));
449         items.push_back (MenuElem (_("Normal"), bind (mem_fun (*this, &TimeAxisView::set_height), Normal)));
450         items.push_back (MenuElem (_("Smaller"), bind (mem_fun (*this, &TimeAxisView::set_height), Smaller)));
451         items.push_back (MenuElem (_("Small"), bind (mem_fun (*this, &TimeAxisView::set_height), Small)));
452 }
453
454 void
455 TimeAxisView::build_display_menu ()
456 {
457         using namespace Menu_Helpers;
458
459         display_menu = new Menu;
460         display_menu->set_name ("ArdourContextMenu");
461
462         // Just let implementing classes define what goes into the manu
463 }
464
465 void
466 TimeAxisView::set_samples_per_unit (double spu)
467 {
468         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
469                 (*i)->set_samples_per_unit (spu);
470         }
471 }
472
473 void
474 TimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
475 {
476         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
477                 (*i)->show_timestretch (start, end);
478         }
479 }
480
481 void
482 TimeAxisView::hide_timestretch ()
483 {
484         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
485                 (*i)->hide_timestretch ();
486         }
487 }
488
489 void
490 TimeAxisView::show_selection (TimeSelection& ts)
491 {
492         double x1;
493         double x2;
494         double y2;
495         SelectionRect *rect;
496
497         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
498                 (*i)->show_selection (ts);
499         }
500
501         if (GTK_OBJECT_FLAGS(GTK_OBJECT(selection_group)) & GNOME_CANVAS_ITEM_VISIBLE) {
502                 while (!used_selection_rects.empty()) {
503                         free_selection_rects.push_front (used_selection_rects.front());
504                         used_selection_rects.pop_front();
505                         gnome_canvas_item_hide (free_selection_rects.front()->rect);
506                         gnome_canvas_item_hide (free_selection_rects.front()->start_trim);
507                         gnome_canvas_item_hide (free_selection_rects.front()->end_trim);
508                 }
509                 gnome_canvas_item_hide (selection_group);
510         }
511
512         gnome_canvas_item_show (selection_group);
513         gnome_canvas_item_raise_to_top (selection_group);
514         
515         for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
516                 jack_nframes_t start, end, cnt;
517
518                 start = (*i).start;
519                 end = (*i).end;
520                 cnt = end - start + 1;
521
522                 rect = get_selection_rect ((*i).id);
523                 
524                 x1 = start / editor.get_current_zoom();
525                 x2 = (start + cnt - 1) / editor.get_current_zoom();
526                 y2 = height;
527
528                 gtk_object_set (GTK_OBJECT(rect->rect), 
529                                 "x1", x1,
530                                 "y1", 1.0,
531                                 "x2", x2,
532                                 "y2", y2,
533                                 NULL);
534                 
535                 // trim boxes are at the top for selections
536                 
537                 if (x2 > x1) {
538                         gtk_object_set (GTK_OBJECT(rect->start_trim), 
539                                         "x1", x1,
540                                         "y1", 1.0,
541                                         "x2", x1 + trim_handle_size,
542                                         "y2", 1.0 + trim_handle_size,
543                                         NULL);
544                         gtk_object_set (GTK_OBJECT(rect->end_trim), 
545                                         "x1", x2 - trim_handle_size,
546                                         "y1", 1.0,
547                                         "x2", x2,
548                                         "y2", 1.0 + trim_handle_size,
549                                         NULL);
550                         gnome_canvas_item_show (rect->start_trim);
551                         gnome_canvas_item_show (rect->end_trim);
552                 } else {
553                         gnome_canvas_item_hide (rect->start_trim);
554                         gnome_canvas_item_hide (rect->end_trim);
555                 }
556
557                 gnome_canvas_item_show (rect->rect);
558                 used_selection_rects.push_back (rect);
559         }
560 }
561
562 void
563 TimeAxisView::reshow_selection (TimeSelection& ts)
564 {
565         show_selection (ts);
566
567         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
568                 (*i)->show_selection (ts);
569         }
570 }
571
572 void
573 TimeAxisView::hide_selection ()
574 {
575         if (GTK_OBJECT_FLAGS(GTK_OBJECT(selection_group)) & GNOME_CANVAS_ITEM_VISIBLE) {
576                 while (!used_selection_rects.empty()) {
577                         free_selection_rects.push_front (used_selection_rects.front());
578                         used_selection_rects.pop_front();
579                         gnome_canvas_item_hide (free_selection_rects.front()->rect);
580                         gnome_canvas_item_hide (free_selection_rects.front()->start_trim);
581                         gnome_canvas_item_hide (free_selection_rects.front()->end_trim);
582                 }
583                 gnome_canvas_item_hide (selection_group);
584         }
585         
586         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
587                 (*i)->hide_selection ();
588         }
589 }
590
591 void
592 TimeAxisView::order_selection_trims (GnomeCanvasItem *item, bool put_start_on_top)
593 {
594         /* find the selection rect this is for. we have the item corresponding to one
595            of the trim handles.
596          */
597
598         for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
599                 if ((*i)->start_trim == item || (*i)->end_trim == item) {
600
601                         /* make one trim handle be "above" the other so that if they overlap,
602                            the top one is the one last used.
603                         */
604
605                         gnome_canvas_item_raise_to_top ((*i)->rect);
606                         gnome_canvas_item_raise_to_top (put_start_on_top ? (*i)->start_trim : (*i)->end_trim);
607                         gnome_canvas_item_raise_to_top (put_start_on_top ? (*i)->end_trim : (*i)->start_trim);
608
609                         break;
610                 }
611         }
612 }
613
614 SelectionRect *
615 TimeAxisView::get_selection_rect (uint32_t id)
616 {
617         SelectionRect *rect;
618
619         /* check to see if we already have a visible rect for this particular selection ID */
620
621         for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
622                 if ((*i)->id == id) {
623                         return (*i);
624                 }
625         }
626
627         /* ditto for the free rect list */
628
629         for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
630                 if ((*i)->id == id) {
631                         free_selection_rects.erase (i);
632                         return (*i);
633                 }
634         }
635
636         /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
637         
638         if (free_selection_rects.empty()) {
639
640                 rect = new SelectionRect;
641
642                 rect->rect = gnome_canvas_item_new (GNOME_CANVAS_GROUP(selection_group),
643                                                   gnome_canvas_simplerect_get_type(),
644                                                   "x1", 0.0,
645                                                   "y1", 0.0,
646                                                   "x2", 0.0,
647                                                   "y2", 0.0,
648                                                   "fill_color_rgba", color_map[cSelectionRectFill],
649                                                   "outline_color_rgba" , color_map[cSelectionRectOutline],
650                                                   NULL);
651                 
652                 
653                 rect->start_trim = gnome_canvas_item_new (GNOME_CANVAS_GROUP(selection_group),
654                                                             gnome_canvas_simplerect_get_type(),
655                                                             "x1", (gdouble) 0.0,
656                                                             "x2", (gdouble) 0.0,
657                                                             "fill_color_rgba" , color_map[cSelectionStartFill],
658                                                             "outline_color_rgba" , color_map[cSelectionStartOutline],
659                                                             NULL);
660                 
661                 rect->end_trim = gnome_canvas_item_new (GNOME_CANVAS_GROUP(selection_group),
662                                                           gnome_canvas_simplerect_get_type(),
663                                                           "x1", 0.0,
664                                                           "x2", 0.0,
665                                                           "fill_color_rgba" , color_map[cSelectionEndFill],
666                                                           "outline_color_rgba" , color_map[cSelectionEndOutline],
667                                                           NULL);
668                 free_selection_rects.push_front (rect);
669
670                 gtk_signal_connect (GTK_OBJECT(rect->rect), "event",
671                                     (GtkSignalFunc) PublicEditor::canvas_selection_rect_event,
672                                     &editor);
673                 gtk_signal_connect (GTK_OBJECT(rect->start_trim), "event",
674                                     (GtkSignalFunc) PublicEditor::canvas_selection_start_trim_event,
675                                     &editor);
676                 gtk_signal_connect (GTK_OBJECT(rect->end_trim), "event",
677                                     (GtkSignalFunc) PublicEditor::canvas_selection_end_trim_event,
678                                     &editor);
679
680                 gtk_object_set_data(GTK_OBJECT(rect->rect), "rect", rect);
681                 gtk_object_set_data(GTK_OBJECT(rect->start_trim), "rect", rect);
682                 gtk_object_set_data(GTK_OBJECT(rect->end_trim), "rect", rect);
683         } 
684
685         rect = free_selection_rects.front();
686         rect->id = id;
687         free_selection_rects.pop_front();
688         return rect;
689 }
690
691 bool
692 TimeAxisView::is_child (TimeAxisView* tav)
693 {
694         return find (children.begin(), children.end(), tav) != children.end();
695 }
696
697 void
698 TimeAxisView::add_child (TimeAxisView* child)
699 {
700         children.push_back (child);
701 }
702
703 void
704 TimeAxisView::remove_child (TimeAxisView* child)
705 {
706         vector<TimeAxisView*>::iterator i;
707
708         if ((i = find (children.begin(), children.end(), child)) != children.end()) {
709                 children.erase (i);
710         }
711 }
712
713 void
714 TimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& result)
715 {
716         return;
717 }
718
719 void
720 TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
721 {
722         return;
723 }
724
725 bool
726 TimeAxisView::touched (double top, double bot)
727 {
728         /* remember: this is X Window - coordinate space starts in upper left and moves down.
729            y_position is the "origin" or "top" of the track.
730          */
731
732         double mybot = y_position + height; // XXX need to include Editor::track_spacing; 
733         
734         return ((y_position <= bot && y_position >= top) || 
735                 ((mybot <= bot) && (top < mybot)) || 
736                 (mybot >= bot && y_position < top));
737 }               
738
739 void
740 TimeAxisView::set_parent (TimeAxisView& p)
741 {
742         parent = &p;
743 }
744
745 bool
746 TimeAxisView::has_state () const
747 {
748         return _has_state;
749 }
750
751 TimeAxisView*
752 TimeAxisView::get_parent_with_state ()
753 {
754         if (parent == 0) {
755                 return 0;
756         }
757
758         if (parent->has_state()) {
759                 return parent;
760         } 
761
762         return parent->get_parent_with_state ();
763 }               
764
765 void
766 TimeAxisView::set_state (const XMLNode& node)
767 {
768         const XMLProperty *prop;
769
770         if ((prop = node.property ("track_height")) != 0) {
771
772                 if (prop->value() == "largest") {
773                         set_height (Largest);
774                 } else if (prop->value() == "large") {
775                         set_height (Large);
776                 } else if (prop->value() == "larger") {
777                         set_height (Larger);
778                 } else if (prop->value() == "normal") {
779                         set_height (Normal);
780                 } else if (prop->value() == "smaller") {
781                         set_height (Smaller);
782                 } else if (prop->value() == "small") {
783                         set_height (Small);
784                 } else {
785                         error << compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
786                         set_height (Normal);
787                 }
788
789         } else {
790                 set_height (Normal);
791         }
792 }
793
794 void
795 TimeAxisView::reset_height()
796 {
797         set_height ((TrackHeight) height);
798
799         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
800                 (*i)->set_height ((TrackHeight)(*i)->height);
801         }
802 }
803