Merged revisions 6293,6296-6306,6308 via svnmerge from
[ardour.git] / libs / gtkmm2 / gtk / src / scale.ccg
1 // -*- c++ -*-
2 /* $Id: scale.ccg,v 1.2 2004/01/19 19:48:44 murrayc Exp $ */
3
4 /* 
5  *
6  * Copyright 1998-2002 The gtkmm Development Team
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <gtkmm/adjustment.h>
24
25 #include <gtk/gtkscale.h>
26 #include <gtk/gtkhscale.h>
27 #include <gtk/gtkvscale.h>
28 #include <math.h>
29
30 namespace Gtk
31 {
32
33 int Scale::calc_digits_(double step) const
34 {
35   int digits = 0;
36
37   //Copied from gtk_[h|v]scale_new_with_range():
38   if (fabs (step) >= 1.0 || step == 0.0)
39      digits = 0;
40   else {
41     digits = abs ((int) floor (log10 (fabs (step))));
42     if (digits > 5)
43       digits = 5;
44   }
45
46   return digits;
47 }
48
49 VScale::VScale(double min, double max, double step)
50 :
51   _CONSTRUCT_SPECIFIC(Scale, VScale)
52 {
53   Adjustment* adjustment = manage(new Adjustment(min, min, max, step, 10 * step, step));
54   // The adjustment will be destroyed along with the object
55   set_adjustment(*adjustment);
56
57   set_digits( calc_digits_(step) );
58 }
59
60 VScale::VScale(Adjustment& adjustment)
61 :
62   _CONSTRUCT_SPECIFIC(Scale, VScale)
63 {
64   set_adjustment(adjustment);
65 }
66
67 VScale::VScale()
68 :
69   _CONSTRUCT_SPECIFIC(Scale, VScale)
70 {
71   Adjustment* adjustment = manage(new Adjustment(0.0, 0.0, 0.0,
72                                                   0.0, 0.0, 0.0));
73   // The adjustment will be destroyed along with the object
74   set_adjustment(*adjustment);
75 }
76
77
78 HScale::HScale(double min, double max, double step)
79 :
80   _CONSTRUCT_SPECIFIC(Scale, HScale)
81 {
82   Adjustment* adjustment = manage(new Adjustment(min, min, max, step, 10 * step, step));
83   // The adjustment will be destroyed along with the object
84   set_adjustment(*adjustment);
85
86   set_digits( calc_digits_(step) );
87 }
88
89 HScale::HScale()
90 :
91   _CONSTRUCT_SPECIFIC(Scale, HScale)
92 {
93   Adjustment* adjustment = manage(new Adjustment(0.0, 0.0, 0.0,
94                                                   0.0, 0.0, 0.0));
95   // The adjustment will be destroyed along with the object
96   set_adjustment(*adjustment);
97 }
98
99 HScale::HScale(Adjustment& adjustment)
100 :
101   _CONSTRUCT_SPECIFIC(Scale, HScale)
102 {
103   set_adjustment(adjustment);
104 }
105
106 } // namespace Gtk
107