]> Pileus Git - ~andy/gtk/blob - gtk/gtkhscale.c
Enhanced GtkWidget documentation with regards to height-for-width geometry management.
[~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 #include "gtkhscale.h"
33 #include "gtkorientable.h"
34
35
36 G_DEFINE_TYPE (GtkHScale, gtk_hscale, GTK_TYPE_SCALE)
37
38 static void
39 gtk_hscale_class_init (GtkHScaleClass *class)
40 {
41   GtkRangeClass *range_class = GTK_RANGE_CLASS (class);
42
43   range_class->slider_detail = "hscale";
44 }
45
46 static void
47 gtk_hscale_init (GtkHScale *hscale)
48 {
49   gtk_orientable_set_orientation (GTK_ORIENTABLE (hscale),
50                                   GTK_ORIENTATION_HORIZONTAL);
51 }
52
53 GtkWidget *
54 gtk_hscale_new (GtkAdjustment *adjustment)
55 {
56   g_return_val_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment),
57                         NULL);
58
59   return g_object_new (GTK_TYPE_HSCALE,
60                        "adjustment", adjustment,
61                        NULL);
62 }
63
64 /**
65  * gtk_hscale_new_with_range:
66  * @min: minimum value
67  * @max: maximum value
68  * @step: step increment (tick size) used with keyboard shortcuts
69  *
70  * Creates a new horizontal scale widget that lets the user input a
71  * number between @min and @max (including @min and @max) with the
72  * increment @step.  @step must be nonzero; it's the distance the
73  * slider moves when using the arrow keys to adjust the scale value.
74  *
75  * Note that the way in which the precision is derived works best if @step
76  * is a power of ten. If the resulting precision is not suitable for your
77  * needs, use gtk_scale_set_digits() to correct it.
78  *
79  * Return value: a new #GtkHScale
80  **/
81 GtkWidget *
82 gtk_hscale_new_with_range (gdouble min,
83                            gdouble max,
84                            gdouble step)
85 {
86   GtkAdjustment *adj;
87   GtkScale *scale;
88   gint digits;
89
90   g_return_val_if_fail (min < max, NULL);
91   g_return_val_if_fail (step != 0.0, NULL);
92
93   adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
94
95   if (fabs (step) >= 1.0 || step == 0.0)
96     {
97       digits = 0;
98     }
99   else
100     {
101       digits = abs ((gint) floor (log10 (fabs (step))));
102       if (digits > 5)
103         digits = 5;
104     }
105
106   scale = g_object_new (GTK_TYPE_HSCALE,
107                         "adjustment", adj,
108                         "digits", digits,
109                         NULL);
110
111   return GTK_WIDGET (scale);
112 }