2 * Copyright (C) 2004 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <pbd/controllable.h>
29 #include "gtkmm2ext/gtk_ui.h"
30 #include "gtkmm2ext/utils.h"
31 #include "gtkmm2ext/keyboard.h"
32 #include "gtkmm2ext/cairo_widget.h"
34 #include "widgets/barcontroller.h"
40 using namespace Gtkmm2ext;
41 using namespace ArdourWidgets;
43 BarController::BarController (Gtk::Adjustment& adj,
44 boost::shared_ptr<PBD::Controllable> mc)
45 : _slider (&adj, mc, 60, 16)
47 , _switch_on_release (false)
50 add_events (Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
51 set (.5, .5, 1.0, 1.0);
53 _slider.set_tweaks (ArdourFader::NoShowUnityLine);
55 _slider.StartGesture.connect (sigc::mem_fun(*this, &BarController::passtrhu_gesture_start));
56 _slider.StopGesture.connect (sigc::mem_fun(*this, &BarController::passtrhu_gesture_stop));
57 _slider.OnExpose.connect (sigc::mem_fun(*this, &BarController::before_expose));
58 _slider.set_name (get_name());
60 Gtk::SpinButton& spinner = _slider.get_spin_button();
61 spinner.signal_activate().connect (mem_fun (*this, &BarController::entry_activated));
62 spinner.signal_focus_out_event().connect (mem_fun (*this, &BarController::entry_focus_out));
63 spinner.set_digits (4);
64 spinner.set_numeric (true);
65 spinner.set_name ("BarControlSpinner");
70 BarController::~BarController ()
75 BarController::on_button_press_event (GdkEventButton* ev)
77 if (get_child() != &_slider) {
80 if (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
81 _switch_on_release = true;
84 _switch_on_release = false;
90 BarController::on_button_release_event (GdkEventButton* ev)
92 if (get_child() != &_slider) {
95 if (ev->button == 1 && _switch_on_release) {
96 Glib::signal_idle().connect (mem_fun (*this, &BarController::switch_to_spinner));
103 BarController::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
105 _slider.set_name (get_name());
109 BarController::switch_to_bar ()
111 if (_switching || get_child() == &_slider) {
118 _slider.queue_draw ();
120 SpinnerActive (false); /* EMIT SIGNAL */
125 BarController::switch_to_spinner ()
127 if (_switching || get_child() != &_slider) {
132 Gtk::SpinButton& spinner = _slider.get_spin_button();
133 if (spinner.get_parent()) {
134 spinner.get_parent()->remove(spinner);
139 spinner.select_region (0, spinner.get_text_length());
140 spinner.grab_focus ();
142 SpinnerActive (true); /* EMIT SIGNAL */
147 BarController::entry_activated ()
153 BarController::entry_focus_out (GdkEventFocus* /*ev*/)
160 BarController::before_expose ()
163 _slider.set_text (get_label (xpos), false, false);
167 BarController::set_sensitive (bool yn)
169 Alignment::set_sensitive (yn);
170 _slider.set_sensitive (yn);