ardour
barcontroller.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004 Paul Davis
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; either version 2 of the License, or
6  (at your option) any later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17 
18 #include <string>
19 #include <sstream>
20 #include <climits>
21 #include <cstdio>
22 #include <cmath>
23 #include <algorithm>
24 
25 #include <pbd/controllable.h>
26 #include <pbd/locale_guard.h>
27 
28 #include "gtkmm2ext/gtk_ui.h"
29 #include "gtkmm2ext/utils.h"
30 #include "gtkmm2ext/keyboard.h"
32 #include "gtkmm2ext/cairo_widget.h"
33 
34 #include "i18n.h"
35 
36 using namespace std;
37 using namespace Gtk;
38 using namespace Gtkmm2ext;
39 
40 BarController::BarController (Gtk::Adjustment& adj,
42  : _slider (&adj, mc, 60, 16)
43  , _switching (false)
44  , _switch_on_release (false)
45 {
46 
47  add_events (Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
48  set (.5, .5, 1.0, 1.0);
49  set_border_width (0);
51 
52  _slider.StartGesture.connect (sigc::mem_fun(*this, &BarController::passtrhu_gesture_start));
53  _slider.StopGesture.connect (sigc::mem_fun(*this, &BarController::passtrhu_gesture_stop));
54  _slider.OnExpose.connect (sigc::mem_fun(*this, &BarController::before_expose));
55  _slider.set_name (get_name());
56 
57  Gtk::SpinButton& spinner = _slider.get_spin_button();
58  spinner.signal_activate().connect (mem_fun (*this, &BarController::entry_activated));
59  spinner.signal_focus_out_event().connect (mem_fun (*this, &BarController::entry_focus_out));
60  spinner.set_digits (9);
61  spinner.set_numeric (true);
62  spinner.set_name ("BarControlSpinner");
63  add (_slider);
64  show_all ();
65 }
66 
68 {
69 }
70 
71 bool
73 {
74  if (get_child() != &_slider) {
75  return false;
76  }
77  if (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
78  _switch_on_release = true;
79  return true;
80  } else {
81  _switch_on_release = false;
82  }
83  return false;
84 }
85 
86 bool
88 {
89  if (get_child() != &_slider) {
90  return false;
91  }
92  if (ev->button == 1 && _switch_on_release) {
93  Glib::signal_idle().connect (mem_fun (*this, &BarController::switch_to_spinner));
94  return true;
95  }
96  return false;
97 }
98 
99 void
100 BarController::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
101 {
102  _slider.set_name (get_name());
103 }
104 
105 gint
107 {
108  if (_switching || get_child() == &_slider) {
109  return FALSE;
110  }
111  _switching = true;
112  remove ();
113  add (_slider);
114  _slider.show ();
115  _slider.queue_draw ();
116  _switching = false;
117  SpinnerActive (false); /* EMIT SIGNAL */
118  return FALSE;
119 }
120 
121 gint
123 {
124  if (_switching || get_child() != &_slider) {
125  return FALSE;
126  }
127 
128  _switching = true;
129  Gtk::SpinButton& spinner = _slider.get_spin_button();
130  if (spinner.get_parent()) {
131  spinner.get_parent()->remove(spinner);
132  }
133  remove ();
134  add (spinner);
135  spinner.show ();
136  spinner.select_region (0, spinner.get_text_length());
137  spinner.grab_focus ();
138  _switching = false;
139  SpinnerActive (true); /* EMIT SIGNAL */
140  return FALSE;
141 }
142 
143 void
145 {
146  switch_to_bar ();
147 }
148 
149 bool
150 BarController::entry_focus_out (GdkEventFocus* /*ev*/)
151 {
152  entry_activated ();
153  return true;
154 }
155 
156 void
158 {
159  double xpos = -1;
160  _slider.set_text (get_label (xpos), false, false);
161 }
162 
163 void
165 {
167  _slider.set_sensitive (yn);
168 }
Gtk::SpinButton & get_spin_button()
sigc::signal< void > StartGesture
Definition: pixfader.h:40
Definition: ardour_ui.h:130
void set_tweaks(Tweaks)
Definition: pixfader.cc:642
Definition: Beats.hpp:239
bool on_button_release_event(GdkEventButton *)
LIBGTKMM2EXT_API void set_sensitive(std::vector< Glib::RefPtr< Gtk::Action > > &actions, bool)
bool entry_focus_out(GdkEventFocus *)
sigc::signal< void, bool > SpinnerActive
Definition: barcontroller.h:52
void on_style_changed(const Glib::RefPtr< Gtk::Style > &)
void set_text(const std::string &, bool centered=true, bool expose=true)
Definition: pixfader.cc:655
HSliderController _slider
Definition: barcontroller.h:64
bool on_button_press_event(GdkEventButton *)
virtual std::string get_label(double &)
Definition: barcontroller.h:59
sigc::signal< void > OnExpose
Definition: pixfader.h:42
sigc::signal< void > StopGesture
Definition: pixfader.h:41