]> Pileus Git - ~andy/gtk/blob - gtk/gtkvscale.c
Merge branch 'master' into toolpalette
[~andy/gtk] / gtk / gtkvscale.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2001 Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25  */
26
27 #include "config.h"
28
29 #include <math.h>
30 #include <stdlib.h>
31
32 #include "gtkvscale.h"
33 #include "gtkorientable.h"
34 #include "gtkalias.h"
35
36
37 G_DEFINE_TYPE (GtkVScale, gtk_vscale, GTK_TYPE_SCALE)
38
39 static void
40 gtk_vscale_class_init (GtkVScaleClass *class)
41 {
42   GtkRangeClass *range_class = GTK_RANGE_CLASS (class);
43
44   range_class->slider_detail = "vscale";
45 }
46
47 static void
48 gtk_vscale_init (GtkVScale *vscale)
49 {
50   gtk_orientable_set_orientation (GTK_ORIENTABLE (vscale),
51                                   GTK_ORIENTATION_VERTICAL);
52 }
53
54 GtkWidget *
55 gtk_vscale_new (GtkAdjustment *adjustment)
56 {
57   g_return_val_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment),
58                         NULL);
59
60   return g_object_new (GTK_TYPE_VSCALE,
61                        "adjustment", adjustment,
62                        NULL);
63 }
64
65 /**
66  * gtk_vscale_new_with_range:
67  * @min: minimum value
68  * @max: maximum value
69  * @step: step increment (tick size) used with keyboard shortcuts
70  *
71  * Creates a new vertical scale widget that lets the user input a
72  * number between @min and @max (including @min and @max) with the
73  * increment @step.  @step must be nonzero; it's the distance the
74  * slider moves when using the arrow keys to adjust the scale value.
75  *
76  * Note that the way in which the precision is derived works best if @step
77  * is a power of ten. If the resulting precision is not suitable for your
78  * needs, use gtk_scale_set_digits() to correct it.
79  *
80  * Return value: a new #GtkVScale
81  **/
82 GtkWidget *
83 gtk_vscale_new_with_range (gdouble min,
84                            gdouble max,
85                            gdouble step)
86 {
87   GtkObject *adj;
88   GtkScale *scale;
89   gint digits;
90
91   g_return_val_if_fail (min < max, NULL);
92   g_return_val_if_fail (step != 0.0, NULL);
93
94   adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
95
96   if (fabs (step) >= 1.0 || step == 0.0)
97     {
98       digits = 0;
99     }
100   else
101     {
102       digits = abs ((gint) floor (log10 (fabs (step))));
103       if (digits > 5)
104         digits = 5;
105     }
106
107   scale = g_object_new (GTK_TYPE_VSCALE,
108                         "adjustment", adj,
109                         "digits", digits,
110                         NULL);
111
112   return GTK_WIDGET (scale);
113 }
114
115 #define __GTK_VSCALE_C__
116 #include "gtkaliasdef.c"