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