2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004 Paul Davis
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string>
|
2009-10-01 12:42:02 -04:00
|
|
|
#include <sstream>
|
2008-06-02 17:41:35 -04:00
|
|
|
#include <climits>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cmath>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <pbd/controllable.h>
|
2010-08-16 15:58:34 -04:00
|
|
|
#include <pbd/locale_guard.h>
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-10 18:01:45 -05:00
|
|
|
#include "gtkmm2ext/gtk_ui.h"
|
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
#include "gtkmm2ext/keyboard.h"
|
|
|
|
#include "gtkmm2ext/barcontroller.h"
|
2014-08-27 12:58:09 -04:00
|
|
|
#include "gtkmm2ext/cairo_widget.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
|
|
|
|
BarController::BarController (Gtk::Adjustment& adj,
|
2014-09-01 23:09:51 -04:00
|
|
|
boost::shared_ptr<PBD::Controllable> mc)
|
|
|
|
: _slider (&adj, 60, 16)
|
|
|
|
, _logarithmic (false)
|
|
|
|
, _switching (false)
|
|
|
|
, _switch_on_release (false)
|
|
|
|
{
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-09-01 23:09:51 -04:00
|
|
|
add_events (Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
|
2014-08-31 13:36:41 -04:00
|
|
|
set (.5, .5, 1.0, 1.0);
|
2014-09-01 23:09:51 -04:00
|
|
|
set_border_width (0);
|
|
|
|
_slider.set_controllable (mc);
|
2014-09-04 20:24:19 -04:00
|
|
|
_slider.set_tweaks (PixFader::NoShowUnityLine);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-09-01 23:09:51 -04:00
|
|
|
_slider.StartGesture.connect (sigc::mem_fun(*this, &BarController::passtrhu_gesture_start));
|
|
|
|
_slider.StopGesture.connect (sigc::mem_fun(*this, &BarController::passtrhu_gesture_stop));
|
|
|
|
_slider.OnExpose.connect (sigc::mem_fun(*this, &BarController::before_expose));
|
2014-09-02 20:38:18 -04:00
|
|
|
_slider.set_name (get_name());
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-09-01 23:09:51 -04:00
|
|
|
Gtk::SpinButton& spinner = _slider.get_spin_button();
|
2008-06-02 17:41:35 -04:00
|
|
|
spinner.signal_activate().connect (mem_fun (*this, &BarController::entry_activated));
|
|
|
|
spinner.signal_focus_out_event().connect (mem_fun (*this, &BarController::entry_focus_out));
|
2009-05-20 09:28:30 -04:00
|
|
|
spinner.signal_input().connect (mem_fun (*this, &BarController::entry_input));
|
|
|
|
spinner.signal_output().connect (mem_fun (*this, &BarController::entry_output));
|
2011-03-17 13:22:52 -04:00
|
|
|
spinner.set_digits (9);
|
2009-10-01 12:42:02 -04:00
|
|
|
spinner.set_numeric (true);
|
2014-09-01 23:09:51 -04:00
|
|
|
spinner.set_name ("BarControlSpinner");
|
|
|
|
add (_slider);
|
2008-06-02 17:41:35 -04:00
|
|
|
show_all ();
|
|
|
|
}
|
|
|
|
|
2012-12-06 15:48:44 -05:00
|
|
|
BarController::~BarController ()
|
|
|
|
{
|
2014-08-27 12:58:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-09-01 23:09:51 -04:00
|
|
|
BarController::on_button_press_event (GdkEventButton* ev)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-09-01 23:09:51 -04:00
|
|
|
if (get_child() != &_slider) {
|
|
|
|
return false;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2014-09-01 23:09:51 -04:00
|
|
|
if (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
|
|
|
|
_switch_on_release = true;
|
2008-06-02 17:41:35 -04:00
|
|
|
return true;
|
2014-09-01 23:09:51 -04:00
|
|
|
} else {
|
|
|
|
_switch_on_release = false;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-09-01 23:09:51 -04:00
|
|
|
BarController::on_button_release_event (GdkEventButton* ev)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-09-01 23:09:51 -04:00
|
|
|
if (get_child() != &_slider) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return false;
|
|
|
|
}
|
2014-09-01 23:09:51 -04:00
|
|
|
if (ev->button == 1 && _switch_on_release) {
|
|
|
|
Glib::signal_idle().connect (mem_fun (*this, &BarController::switch_to_spinner));
|
2008-06-02 17:41:35 -04:00
|
|
|
return true;
|
|
|
|
}
|
2014-09-01 23:09:51 -04:00
|
|
|
return false;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2014-09-02 20:38:18 -04:00
|
|
|
void
|
|
|
|
BarController::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
|
|
|
|
{
|
|
|
|
_slider.set_name (get_name());
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
gint
|
|
|
|
BarController::switch_to_bar ()
|
|
|
|
{
|
2014-09-01 23:09:51 -04:00
|
|
|
if (_switching || get_child() == &_slider) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-01 23:09:51 -04:00
|
|
|
_switching = true;
|
2008-06-02 17:41:35 -04:00
|
|
|
remove ();
|
2014-09-01 23:09:51 -04:00
|
|
|
add (_slider);
|
|
|
|
_slider.show ();
|
|
|
|
_slider.queue_draw ();
|
|
|
|
_switching = false;
|
2010-11-25 19:29:12 -05:00
|
|
|
SpinnerActive (false); /* EMIT SIGNAL */
|
2008-06-02 17:41:35 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
BarController::switch_to_spinner ()
|
|
|
|
{
|
2014-09-01 23:09:51 -04:00
|
|
|
if (_switching || get_child() != &_slider) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-09-01 23:09:51 -04:00
|
|
|
_switching = true;
|
|
|
|
Gtk::SpinButton& spinner = _slider.get_spin_button();
|
|
|
|
if (spinner.get_parent()) {
|
|
|
|
spinner.get_parent()->remove(spinner);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
remove ();
|
|
|
|
add (spinner);
|
|
|
|
spinner.show ();
|
|
|
|
spinner.select_region (0, spinner.get_text_length());
|
|
|
|
spinner.grab_focus ();
|
2014-09-01 23:09:51 -04:00
|
|
|
_switching = false;
|
2010-11-25 19:29:12 -05:00
|
|
|
SpinnerActive (true); /* EMIT SIGNAL */
|
2008-06-02 17:41:35 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BarController::entry_activated ()
|
|
|
|
{
|
|
|
|
switch_to_bar ();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-07-21 11:55:17 -04:00
|
|
|
BarController::entry_focus_out (GdkEventFocus* /*ev*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
entry_activated ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-01 23:09:51 -04:00
|
|
|
BarController::before_expose ()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-09-01 23:09:51 -04:00
|
|
|
double xpos = -1;
|
2014-09-02 10:05:21 -04:00
|
|
|
_slider.set_text (get_label (xpos), false, false);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BarController::set_sensitive (bool yn)
|
|
|
|
{
|
2014-08-31 13:36:41 -04:00
|
|
|
Alignment::set_sensitive (yn);
|
2014-09-01 23:09:51 -04:00
|
|
|
_slider.set_sensitive (yn);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2009-05-20 09:28:30 -04:00
|
|
|
|
2009-10-01 12:42:02 -04:00
|
|
|
/*
|
|
|
|
This is called when we need to update the adjustment with the value
|
|
|
|
from the spinner's text entry.
|
|
|
|
|
|
|
|
We need to use Gtk::Entry::get_text to avoid recursive nastiness :)
|
|
|
|
|
|
|
|
If we're not in logarithmic mode we can return false to use the
|
|
|
|
default conversion.
|
|
|
|
|
|
|
|
In theory we should check for conversion errors but set numeric
|
|
|
|
mode to true on the spinner prevents invalid input.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
BarController::entry_input (double* new_value)
|
2009-05-20 09:28:30 -04:00
|
|
|
{
|
2014-09-01 23:09:51 -04:00
|
|
|
if (!_logarithmic) {
|
2009-10-01 12:42:02 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// extract a double from the string and take its log
|
2014-09-01 23:09:51 -04:00
|
|
|
Gtk::SpinButton& spinner = _slider.get_spin_button();
|
2009-10-01 12:42:02 -04:00
|
|
|
Entry *entry = dynamic_cast<Entry *>(&spinner);
|
|
|
|
double value;
|
2010-08-16 15:58:34 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
// Switch to user's preferred locale so that
|
|
|
|
// if they use different LC_NUMERIC conventions,
|
|
|
|
// we will honor them.
|
|
|
|
|
|
|
|
PBD::LocaleGuard lg ("");
|
|
|
|
sscanf (entry->get_text().c_str(), "%lf", &value);
|
|
|
|
}
|
|
|
|
|
2009-10-01 12:42:02 -04:00
|
|
|
*new_value = log(value);
|
2010-08-16 15:58:34 -04:00
|
|
|
|
2009-10-01 12:42:02 -04:00
|
|
|
return true;
|
2009-05-20 09:28:30 -04:00
|
|
|
}
|
|
|
|
|
2009-10-01 12:42:02 -04:00
|
|
|
/*
|
|
|
|
This is called when we need to update the spinner's text entry
|
|
|
|
with the value of the adjustment.
|
|
|
|
|
|
|
|
We need to use Gtk::Entry::set_text to avoid recursive nastiness :)
|
|
|
|
|
|
|
|
If we're not in logarithmic mode we can return false to use the
|
|
|
|
default conversion.
|
|
|
|
*/
|
2009-05-20 09:28:30 -04:00
|
|
|
bool
|
|
|
|
BarController::entry_output ()
|
|
|
|
{
|
2014-09-01 23:09:51 -04:00
|
|
|
if (!_logarithmic) {
|
2009-10-01 12:42:02 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-01 23:09:51 -04:00
|
|
|
char buf[128];
|
|
|
|
Gtk::SpinButton& spinner = _slider.get_spin_button();
|
|
|
|
|
2009-10-01 12:42:02 -04:00
|
|
|
// generate the exponential and turn it into a string
|
|
|
|
// convert to correct locale.
|
|
|
|
|
|
|
|
stringstream stream;
|
|
|
|
string str;
|
|
|
|
|
2010-08-16 15:58:34 -04:00
|
|
|
{
|
|
|
|
// Switch to user's preferred locale so that
|
|
|
|
// if they use different LC_NUMERIC conventions,
|
|
|
|
// we will honor them.
|
|
|
|
|
|
|
|
PBD::LocaleGuard lg ("");
|
|
|
|
snprintf (buf, sizeof (buf), "%g", exp (spinner.get_adjustment()->get_value()));
|
2009-10-01 12:42:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Entry *entry = dynamic_cast<Entry *>(&spinner);
|
2010-08-16 15:58:34 -04:00
|
|
|
entry->set_text(buf);
|
2009-10-01 12:42:02 -04:00
|
|
|
|
|
|
|
return true;
|
2009-05-20 09:28:30 -04:00
|
|
|
}
|