Improve sensitization of buttons in the advanced options
[ardour.git] / gtk2_ardour / time_info_box.cc
index 7ee144015f17a988ced00b781a6a4edc3db555ce..2cb7e652b59c2187af0275b453c63062a4b06c79 100644 (file)
@@ -32,6 +32,8 @@
 #include "time_info_box.h"
 #include "audio_clock.h"
 #include "editor.h"
+#include "control_point.h"
+#include "automation_line.h"
 
 #include "i18n.h"
 
@@ -142,15 +144,7 @@ TimeInfoBox::TimeInfoBox ()
        Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
        Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
 
-       Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), ui_bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
-
-       Gdk::Color bg;
-
-       bg.set_red (lrint (0.149 * 65535));
-       bg.set_green (lrint (0.149 * 65535));
-       bg.set_blue (lrint (0.149 * 65535));
-
-       CairoWidget::provide_background_for_cairo_widget (*this, bg);
+       Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), boost::bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
 }
 
 TimeInfoBox::~TimeInfoBox ()
@@ -255,15 +249,29 @@ TimeInfoBox::selection_changed ()
                } else {
                        if (selection.regions.empty()) {
                                if (selection.points.empty()) {
-                                       selection_start->set_off (true);
-                                       selection_end->set_off (true);
-                                       selection_length->set_off (true);
+                                       Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
+                                       Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+
+                                       if (tact && tact->get_active() && !selection.time.empty()) {
+                                               /* show selected range */
+                                               selection_start->set_off (false);
+                                               selection_end->set_off (false);
+                                               selection_length->set_off (false);
+                                               selection_start->set (selection.time.start());
+                                               selection_end->set (selection.time.end_frame());
+                                               selection_length->set (selection.time.length());
+                                       } else {
+                                               selection_start->set_off (true);
+                                               selection_end->set_off (true);
+                                               selection_length->set_off (true);
+                                       }
                                } else {
                                        s = max_framepos;
                                        e = 0;
                                        for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
-                                               s = min (s, (framepos_t) i->start);
-                                               e = max (e, (framepos_t) i->end);
+                                               framepos_t const p = (*i)->line().session_position ((*i)->model ());
+                                               s = min (s, p);
+                                               e = max (e, p);
                                        }
                                        selection_start->set_off (false);
                                        selection_end->set_off (false);
@@ -287,9 +295,24 @@ TimeInfoBox::selection_changed ()
 
        case Editing::MouseRange:
                if (selection.time.empty()) {
-                       selection_start->set_off (true);
-                       selection_end->set_off (true);
-                       selection_length->set_off (true);
+                       Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
+                       Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+
+                       if (tact && tact->get_active() &&  !selection.regions.empty()) {        
+                               /* show selected regions */
+                               s = selection.regions.start();
+                               e = selection.regions.end_frame();
+                               selection_start->set_off (false);
+                               selection_end->set_off (false);
+                               selection_length->set_off (false);
+                               selection_start->set (s);
+                               selection_end->set (e);
+                               selection_length->set (e - s + 1);
+                       } else {
+                               selection_start->set_off (true);
+                               selection_end->set_off (true);
+                               selection_length->set_off (true);
+                       }
                } else {
                        selection_start->set_off (false);
                        selection_end->set_off (false);
@@ -343,31 +366,3 @@ TimeInfoBox::punch_changed (Location* loc)
        punch_end->set (loc->end());
 }      
 
-bool
-TimeInfoBox::on_expose_event (GdkEventExpose* ev)
-{
-       {
-               int x, y;
-               Gtk::Widget* window_parent;
-               Glib::RefPtr<Gdk::Window> win = Gtkmm2ext::window_to_draw_on (*this, &window_parent);
-
-               if (win) {
-               
-                       Cairo::RefPtr<Cairo::Context> context = win->create_cairo_context();
-
-#if 0                  
-                       translate_coordinates (*window_parent, ev->area.x, ev->area.y, x, y);
-                       context->rectangle (x, y, ev->area.width, ev->area.height);
-                       context->clip ();
-#endif
-                       translate_coordinates (*window_parent, 0, 0, x, y);
-                       context->set_source_rgba (0.149, 0.149, 0.149, 1.0);
-                       Gtkmm2ext::rounded_rectangle (context, x, y, get_allocation().get_width(), get_allocation().get_height(), 9);
-                       context->fill ();
-               }
-       }
-
-       HBox::on_expose_event (ev);
-
-       return false;
-}