]> Pileus Git - ~andy/gtk/blob - gtk/gtkhscale.c
e19a5b6b043330b2650579942726d00c0fa420b2
[~andy/gtk] / gtk / gtkhscale.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 #undef GTK_DISABLE_DEPRECATED
33 #include "gtkhscale.h"
34 #include "gtkorientable.h"
35
36
37 /**
38  * SECTION:gtkhscale
39  * @Short_description: A horizontal slider widget for selecting a value from a range
40  * @Title: GtkHScale
41  *
42  * The #GtkHScale widget is used to allow the user to select a value using
43  * a horizontal slider. To create one, use gtk_hscale_new_with_range().
44  *
45  * The position to show the current value, and the number of decimal places
46  * shown can be set using the parent #GtkScale class's functions.
47  *
48  * GtkHScale has been deprecated, use #GtkScale instead.
49  */
50
51
52 G_DEFINE_TYPE (GtkHScale, gtk_hscale, GTK_TYPE_SCALE)
53
54 static void
55 gtk_hscale_class_init (GtkHScaleClass *class)
56 {
57   GtkRangeClass *range_class = GTK_RANGE_CLASS (class);
58
59   range_class->slider_detail = "hscale";
60 }
61
62 static void
63 gtk_hscale_init (GtkHScale *hscale)
64 {
65   gtk_orientable_set_orientation (GTK_ORIENTABLE (hscale),
66                                   GTK_ORIENTATION_HORIZONTAL);
67 }
68
69 /**
70  * gtk_hscale_new:
71  * @adjustment: the #GtkAdjustment which sets the range of the scale.
72  *
73  * Creates a new #GtkHScale.
74  *
75  * Returns: a new #GtkHScale.
76  *
77  * Deprecated: 3.2: Use gtk_scale_new() with %GTK_ORIENTATION_HORIZONTAL instead
78  */
79 GtkWidget *
80 gtk_hscale_new (GtkAdjustment *adjustment)
81 {
82   g_return_val_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment),
83                         NULL);
84
85   return g_object_new (GTK_TYPE_HSCALE,
86                        "adjustment", adjustment,
87                        NULL);
88 }
89
90 /**
91  * gtk_hscale_new_with_range:
92  * @min: minimum value
93  * @max: maximum value
94  * @step: step increment (tick size) used with keyboard shortcuts
95  *
96  * Creates a new horizontal scale widget that lets the user input a
97  * number between @min and @max (including @min and @max) with the
98  * increment @step.  @step must be nonzero; it's the distance the
99  * slider moves when using the arrow keys to adjust the scale value.
100  *
101  * Note that the way in which the precision is derived works best if @step
102  * is a power of ten. If the resulting precision is not suitable for your
103  * needs, use gtk_scale_set_digits() to correct it.
104  *
105  * Return value: a new #GtkHScale
106  *
107  * Deprecated: 3.2: Use gtk_scale_new_with_range() with %GTK_ORIENTATION_HORIZONTAL instead
108  **/
109 GtkWidget *
110 gtk_hscale_new_with_range (gdouble min,
111                            gdouble max,
112                            gdouble step)
113 {
114   GtkAdjustment *adj;
115   GtkScale *scale;
116   gint digits;
117
118   g_return_val_if_fail (min < max, NULL);
119   g_return_val_if_fail (step != 0.0, NULL);
120
121   adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
122
123   if (fabs (step) >= 1.0 || step == 0.0)
124     {
125       digits = 0;
126     }
127   else
128     {
129       digits = abs ((gint) floor (log10 (fabs (step))));
130       if (digits > 5)
131         digits = 5;
132     }
133
134   scale = g_object_new (GTK_TYPE_HSCALE,
135                         "adjustment", adj,
136                         "digits", digits,
137                         NULL);
138
139   return GTK_WIDGET (scale);
140 }