partial patch/partial by-hand merge of 2.X commits 3169&3170 to 3.X codebase
[ardour.git] / libs / gtkmm2ext / slider_controller.cc
1 /*
2     Copyright (C) 1998-99 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     $Id$
18 */
19
20 #include <string>
21
22 #include <gtkmm2ext/gtk_ui.h>
23 #include <gtkmm2ext/pixfader.h>
24 #include <gtkmm2ext/slider_controller.h>
25
26 #include "i18n.h"
27
28 using namespace Gtkmm2ext;
29 using namespace PBD;
30
31 SliderController::SliderController (Glib::RefPtr<Gdk::Pixbuf> image,
32                                     Gtk::Adjustment *adj,  int orientation,
33                                     bool with_numeric)
34
35         : PixFader (image, *adj, orientation),
36           spin (*adj, 0, 2)
37 {                         
38         spin.set_name ("SliderControllerValue");
39         spin.set_size_request (70,-1); // should be based on font size somehow
40         spin.set_numeric (true);
41         spin.set_snap_to_ticks (false);
42 }
43
44 void
45 SliderController::set_value (float v)
46 {
47         adjustment.set_value (v);
48 }
49
50 bool 
51 SliderController::on_button_press_event (GdkEventButton *ev) 
52 {
53         if (binding_proxy.button_press_handler (ev)) {
54                 return true;
55         }
56
57         return PixFader::on_button_press_event (ev);
58 }
59
60 VSliderController::VSliderController (Glib::RefPtr<Gdk::Pixbuf> image,
61                                       Gtk::Adjustment *adj,
62                                       bool with_numeric)
63
64         : SliderController (image, adj, VERT, with_numeric)
65 {
66         if (with_numeric) {
67                 spin_frame.add (spin);
68                 spin_frame.set_shadow_type (Gtk::SHADOW_IN);
69                 spin_frame.set_name ("BaseFrame");
70                 spin_hbox.pack_start (spin_frame, false, true);
71                 // pack_start (spin_hbox, false, false);
72         }
73 }
74
75 HSliderController::HSliderController (Glib::RefPtr<Gdk::Pixbuf> image,
76                                       Gtk::Adjustment *adj,
77                                       bool with_numeric)
78         
79         : SliderController (image, adj, HORIZ, with_numeric)
80 {
81         if (with_numeric) {
82                 spin_frame.add (spin);
83                 //spin_frame.set_shadow_type (Gtk::SHADOW_IN);
84                 spin_frame.set_name ("BaseFrame");
85                 spin_hbox.pack_start (spin_frame, false, true);
86                 // pack_start (spin_hbox, false, false);
87         }
88 }