remove all trace of SAE from source code.
[ardour.git] / gtk2_ardour / audio_clock.cc
index 15fd85c229d5eb5d8db35efc995a3a41f3fddf15..5a05b208940800f4d100d8630efdcafe5c432420 100644 (file)
 #include "ardour/tempo.h"
 #include "ardour/types.h"
 
-#include "ardour_ui.h"
 #include "audio_clock.h"
-#include "global_signals.h"
 #include "utils.h"
 #include "keyboard.h"
 #include "gui_thread.h"
+#include "ui_config.h"
 #include "i18n.h"
 
 using namespace ARDOUR;
@@ -55,7 +54,7 @@ using Gtkmm2ext::Keyboard;
 
 sigc::signal<void> AudioClock::ModeChanged;
 vector<AudioClock*> AudioClock::clocks;
-const double AudioClock::info_font_scale_factor = 0.60;
+const double AudioClock::info_font_scale_factor = 0.68;
 const double AudioClock::separator_height = 0.0;
 const double AudioClock::x_leading_padding = 6.0;
 
@@ -65,13 +64,15 @@ const double AudioClock::x_leading_padding = 6.0;
 #define TXTSPAN "<span font-family=\"Sans\" foreground=\"white\">"
 
 AudioClock::AudioClock (const string& clock_name, bool transient, const string& widget_name,
-                       bool allow_edit, bool follows_playhead, bool duration, bool with_info)
+                       bool allow_edit, bool follows_playhead, bool duration, bool with_info,
+                       bool accept_on_focus_out)
        : ops_menu (0)
        , _name (clock_name)
        , is_transient (transient)
        , is_duration (duration)
        , editable (allow_edit)
        , _follows_playhead (follows_playhead)
+       , _accept_on_focus_out (accept_on_focus_out)
        , _off (false)
        , em_width (0)
        , _edit_by_click_field (false)
@@ -119,8 +120,8 @@ AudioClock::AudioClock (const string& clock_name, bool transient, const string&
                clocks.push_back (this);
        }
 
-       ColorsChanged.connect (sigc::mem_fun (*this, &AudioClock::set_colors));
-       DPIReset.connect (sigc::mem_fun (*this, &AudioClock::dpi_reset));
+       UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &AudioClock::set_colors));
+       UIConfiguration::instance().DPIReset.connect (sigc::mem_fun (*this, &AudioClock::dpi_reset));
 }
 
 AudioClock::~AudioClock ()
@@ -150,7 +151,7 @@ AudioClock::on_realize ()
        Gtk::Requisition req;
 
        CairoWidget::on_realize ();
-       
+
        set_clock_dimensions (req);
 
        first_width = req.width;
@@ -219,15 +220,15 @@ AudioClock::set_colors ()
        uint32_t cursor_color;
 
        if (active_state()) {
-               bg_color = ARDOUR_UI::config()->color (string_compose ("%1 active: background", get_name()));
-               text_color = ARDOUR_UI::config()->color (string_compose ("%1 active: text", get_name()));
-               editing_color = ARDOUR_UI::config()->color (string_compose ("%1 active: edited text", get_name()));
-               cursor_color = ARDOUR_UI::config()->color (string_compose ("%1 active: cursor", get_name()));
+               bg_color = UIConfiguration::instance().color (string_compose ("%1 active: background", get_name()));
+               text_color = UIConfiguration::instance().color (string_compose ("%1 active: text", get_name()));
+               editing_color = UIConfiguration::instance().color (string_compose ("%1 active: edited text", get_name()));
+               cursor_color = UIConfiguration::instance().color (string_compose ("%1 active: cursor", get_name()));
        } else {
-               bg_color = ARDOUR_UI::config()->color (string_compose ("%1: background", get_name()));
-               text_color = ARDOUR_UI::config()->color (string_compose ("%1: text", get_name()));
-               editing_color = ARDOUR_UI::config()->color (string_compose ("%1: edited text", get_name()));
-               cursor_color = ARDOUR_UI::config()->color (string_compose ("%1: cursor", get_name()));
+               bg_color = UIConfiguration::instance().color (string_compose ("%1: background", get_name()));
+               text_color = UIConfiguration::instance().color (string_compose ("%1: text", get_name()));
+               editing_color = UIConfiguration::instance().color (string_compose ("%1: edited text", get_name()));
+               cursor_color = UIConfiguration::instance().color (string_compose ("%1: cursor", get_name()));
        }
 
        /* store for bg and cursor in render() */
@@ -317,7 +318,7 @@ AudioClock::render (cairo_t* cr, cairo_rectangle_t*)
                cairo_save (cr);
                cairo_scale (cr, xscale, yscale);
        }
-       
+
        pango_cairo_show_layout (cr, _layout->gobj());
 
        if (xscale != 1.0 || yscale != 1.0) {
@@ -334,7 +335,7 @@ AudioClock::render (cairo_t* cr, cairo_rectangle_t*)
 
                if (mode_based_info_ratio != 1.0) {
 
-                       double left_rect_width = round (((get_width() - separator_height) * mode_based_info_ratio) + 0.5);
+                       double left_rect_width = get_left_rect_width();
 
                        if (_need_bg) {
                                if (corner_radius) {
@@ -470,7 +471,10 @@ AudioClock::set_clock_dimensions (Gtk::Requisition& req)
        tmp->set_font_description (font);
 
        /* this string is the longest thing we will ever display */
-       tmp->set_text (" 88:88:88,888");
+       if (_mode == MinSec)
+               tmp->set_text (" 88:88:88,888 ");
+       else
+               tmp->set_text (" 88:88:88,88 ");
        tmp->get_pixel_size (req.width, req.height);
 
        layout_height = req.height;
@@ -503,15 +507,15 @@ AudioClock::on_size_request (Gtk::Requisition* req)
                Glib::RefPtr<Gtk::Style> style = get_style ();
                Pango::FontDescription font;
                int w;
-               
+
                tmp = Pango::Layout::create (get_pango_context());
-               
+
                if (!is_realized()) {
                        font = get_font_for_style (get_name());
                } else {
                        font = style->get_font();
                }
-               
+
                tmp->set_font_description (font);
 
                font.set_size (INFO_FONT_SIZE);
@@ -557,17 +561,17 @@ AudioClock::start_edit (Field f)
                        edit_string.clear ();
                        _layout->set_text ("");
                }
-               
+
                input_string.clear ();
                editing = true;
                edit_is_negative = false;
-               
+
                if (f) {
                        input_string = get_field (f);
                        show_edit_status (merge_input_and_edit_string ());
                        _layout->set_text (edit_string);
                }
-               
+
                queue_draw ();
 
                Keyboard::magic_widget_grab_focus ();
@@ -1415,7 +1419,10 @@ AudioClock::on_key_press_event (GdkEventKey* ev)
                goto use_input_string;
 
        default:
-               return false;
+               /* do not allow other keys to passthru to the rest of the GUI
+                  when editing.
+               */
+               return true;
        }
 
        if (!insert_map.empty() && (input_string.length() >= insert_map.size())) {
@@ -1685,7 +1692,7 @@ AudioClock::on_focus_out_event (GdkEventFocus* ev)
        bool ret = CairoWidget::on_focus_out_event (ev);
 
        if (editing) {
-               end_edit (false);
+               end_edit (_accept_on_focus_out);
        }
 
        return ret;
@@ -2079,6 +2086,24 @@ AudioClock::frames_from_audioframes_string (const string& str) const
        return f;
 }
 
+void
+AudioClock::copy_text_to_clipboard () const
+{
+       string val;
+       if (editing) {
+               val = pre_edit_string;
+       } else {
+               val = _layout->get_text ();
+       }
+       const size_t trim = val.find_first_not_of(" ");
+       if (trim == string::npos) {
+               assert(0); // empty clock, can't be right.
+               return;
+       }
+       Glib::RefPtr<Clipboard> cl = Gtk::Clipboard::get();
+       cl->set_text (val.substr(trim));
+}
+
 void
 AudioClock::build_ops_menu ()
 {
@@ -2087,18 +2112,18 @@ AudioClock::build_ops_menu ()
        MenuList& ops_items = ops_menu->items();
        ops_menu->set_name ("ArdourContextMenu");
 
-       if (!Profile->get_sae()) {
-               ops_items.push_back (MenuElem (_("Timecode"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Timecode)));
-       }
+       ops_items.push_back (MenuElem (_("Timecode"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Timecode)));
        ops_items.push_back (MenuElem (_("Bars:Beats"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), BBT)));
        ops_items.push_back (MenuElem (_("Minutes:Seconds"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), MinSec)));
        ops_items.push_back (MenuElem (_("Samples"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Frames)));
 
        if (editable && !_off && !is_duration && !_follows_playhead) {
                ops_items.push_back (SeparatorElem());
-               ops_items.push_back (MenuElem (_("Set From Playhead"), sigc::mem_fun(*this, &AudioClock::set_from_playhead)));
+               ops_items.push_back (MenuElem (_("Set from Playhead"), sigc::mem_fun(*this, &AudioClock::set_from_playhead)));
                ops_items.push_back (MenuElem (_("Locate to This Time"), sigc::mem_fun(*this, &AudioClock::locate)));
        }
+       ops_items.push_back (SeparatorElem());
+       ops_items.push_back (MenuElem (_("Copy to clipboard"), sigc::mem_fun(*this, &AudioClock::copy_text_to_clipboard)));
 }
 
 void
@@ -2135,6 +2160,9 @@ AudioClock::set_mode (Mode m)
 
        _layout->set_text ("");
 
+       Gtk::Requisition req;
+       set_clock_dimensions (req);
+
        if (_left_layout) {
 
                _left_layout->set_attributes (info_attributes);