]> Pileus Git - ~andy/gtk/blob - gtk/deprecated/gtkvscale.c
entry: Use GtkSelectionWindow for touch text selection
[~andy/gtk] / gtk / deprecated / 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, see <http://www.gnu.org/licenses/>.
16  */
17
18 /*
19  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
20  * file for a list of people on the GTK+ Team.  See the ChangeLog
21  * files for a list of changes.  These files are distributed with
22  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
23  */
24
25 #include "config.h"
26
27 #include <math.h>
28 #include <stdlib.h>
29
30 #include "gtkvscale.h"
31
32 #include "gtkadjustment.h"
33 #include "gtkorientable.h"
34
35
36 /**
37  * SECTION:gtkvscale
38  * @Short_description: A vertical slider widget for selecting a value from a range
39  * @Title: GtkVScale
40  *
41  * The #GtkVScale widget is used to allow the user to select a value using
42  * a vertical slider. To create one, use gtk_hscale_new_with_range().
43  *
44  * The position to show the current value, and the number of decimal places
45  * shown can be set using the parent #GtkScale class's functions.
46  *
47  * GtkVScale has been deprecated, use #GtkScale instead.
48  */
49
50 G_DEFINE_TYPE (GtkVScale, gtk_vscale, GTK_TYPE_SCALE)
51
52 static void
53 gtk_vscale_class_init (GtkVScaleClass *class)
54 {
55   GtkRangeClass *range_class = GTK_RANGE_CLASS (class);
56
57   range_class->slider_detail = "vscale";
58 }
59
60 static void
61 gtk_vscale_init (GtkVScale *vscale)
62 {
63   gtk_orientable_set_orientation (GTK_ORIENTABLE (vscale),
64                                   GTK_ORIENTATION_VERTICAL);
65 }
66 /**
67  * gtk_vscale_new:
68  * @adjustment: the #GtkAdjustment which sets the range of the scale.
69  *
70  * Creates a new #GtkVScale.
71  *
72  * Returns: a new #GtkVScale.
73  *
74  * Deprecated: 3.2: Use gtk_scale_new() with %GTK_ORIENTATION_VERTICAL instead
75  */
76 GtkWidget *
77 gtk_vscale_new (GtkAdjustment *adjustment)
78 {
79   g_return_val_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment),
80                         NULL);
81
82   return g_object_new (GTK_TYPE_VSCALE,
83                        "adjustment", adjustment,
84                        NULL);
85 }
86
87 /**
88  * gtk_vscale_new_with_range:
89  * @min: minimum value
90  * @max: maximum value
91  * @step: step increment (tick size) used with keyboard shortcuts
92  *
93  * Creates a new vertical scale widget that lets the user input a
94  * number between @min and @max (including @min and @max) with the
95  * increment @step.  @step must be nonzero; it's the distance the
96  * slider moves when using the arrow keys to adjust the scale value.
97  *
98  * Note that the way in which the precision is derived works best if @step
99  * is a power of ten. If the resulting precision is not suitable for your
100  * needs, use gtk_scale_set_digits() to correct it.
101  *
102  * Return value: a new #GtkVScale
103  *
104  * Deprecated: 3.2: Use gtk_scale_new_with_range() with %GTK_ORIENTATION_VERTICAL instead
105  **/
106 GtkWidget *
107 gtk_vscale_new_with_range (gdouble min,
108                            gdouble max,
109                            gdouble step)
110 {
111   GtkAdjustment *adj;
112   GtkScale *scale;
113   gint digits;
114
115   g_return_val_if_fail (min < max, NULL);
116   g_return_val_if_fail (step != 0.0, NULL);
117
118   adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
119
120   if (fabs (step) >= 1.0 || step == 0.0)
121     {
122       digits = 0;
123     }
124   else
125     {
126       digits = abs ((gint) floor (log10 (fabs (step))));
127       if (digits > 5)
128         digits = 5;
129     }
130
131   scale = g_object_new (GTK_TYPE_VSCALE,
132                         "adjustment", adj,
133                         "digits", digits,
134                         NULL);
135
136   return GTK_WIDGET (scale);
137 }