]> Pileus Git - ~andy/gtk/blob - gtk/gtkscrollbar.c
01825a98df26cadaaae6d46fb9349df70a5b2780
[~andy/gtk] / gtk / gtkscrollbar.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * Copyright (C) 2001 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
23  * file for a list of people on the GTK+ Team.  See the ChangeLog
24  * files for a list of changes.  These files are distributed with
25  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
26  */
27
28 #include "config.h"
29
30 #include "gtkscrollbar.h"
31 #include "gtkintl.h"
32 #include "gtkprivate.h"
33
34 #include "a11y/gtkscrollbaraccessible.h"
35
36
37 /**
38  * SECTION:gtkscrollbar
39  * @Short_description: A Scrollbar
40  * @Title: GtkScrollbar
41  * @See_also: #GtkAdjustment, #GtkScrolledWindow
42  *
43  * The #GtkScrollbar widget is a horizontal or vertical scrollbar,
44  * depending on the value of the #GtkOrientable:orientation property.
45  *
46  * The position of the thumb in a scrollbar is controlled by the scroll
47  * adjustments. See #GtkAdjustment for the fields in an adjustment - for
48  * #GtkScrollbar, the #GtkAdjustment.value field represents the position
49  * of the scrollbar, which must be between the #GtkAdjustment.lower field
50  * and #GtkAdjustment.upper - #GtkAdjustment.page_size. The
51  * #GtkAdjustment.page_size field represents the size of the visible
52  * scrollable area. The #GtkAdjustment.step_increment and
53  * #GtkAdjustment.page_increment fields are used when the user asks to
54  * step down (using the small stepper arrows) or page down (using for
55  * example the <keycap>PageDown</keycap> key).
56  */
57
58
59 static void gtk_scrollbar_style_updated (GtkWidget *widget);
60
61 G_DEFINE_TYPE (GtkScrollbar, gtk_scrollbar, GTK_TYPE_RANGE)
62
63 static void
64 gtk_scrollbar_class_init (GtkScrollbarClass *class)
65 {
66   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
67
68   widget_class->style_updated = gtk_scrollbar_style_updated;
69
70   gtk_widget_class_install_style_property (widget_class,
71                                            g_param_spec_int ("min-slider-length",
72                                                              P_("Minimum Slider Length"),
73                                                              P_("Minimum length of scrollbar slider"),
74                                                              0,
75                                                              G_MAXINT,
76                                                              21,
77                                                              GTK_PARAM_READABLE));
78
79   gtk_widget_class_install_style_property (widget_class,
80                                            g_param_spec_boolean ("fixed-slider-length",
81                                                                  P_("Fixed slider size"),
82                                                                  P_("Don't change slider size, just lock it to the minimum length"),
83                                                                  FALSE,
84                                                                  GTK_PARAM_READABLE));
85
86   gtk_widget_class_install_style_property (widget_class,
87                                            g_param_spec_boolean ("has-backward-stepper",
88                                                                  P_("Backward stepper"),
89                                                                  P_("Display the standard backward arrow button"),
90                                                                  TRUE,
91                                                                  GTK_PARAM_READABLE));
92
93   gtk_widget_class_install_style_property (widget_class,
94                                            g_param_spec_boolean ("has-forward-stepper",
95                                                                  P_("Forward stepper"),
96                                                                  P_("Display the standard forward arrow button"),
97                                                                  TRUE,
98                                                                  GTK_PARAM_READABLE));
99
100   gtk_widget_class_install_style_property (widget_class,
101                                            g_param_spec_boolean ("has-secondary-backward-stepper",
102                                                                  P_("Secondary backward stepper"),
103                                                                  P_("Display a second backward arrow button on the opposite end of the scrollbar"),
104                                                                  FALSE,
105                                                                  GTK_PARAM_READABLE));
106
107   gtk_widget_class_install_style_property (widget_class,
108                                            g_param_spec_boolean ("has-secondary-forward-stepper",
109                                                                  P_("Secondary forward stepper"),
110                                                                  P_("Display a second forward arrow button on the opposite end of the scrollbar"),
111                                                                  FALSE,
112                                                                  GTK_PARAM_READABLE));
113
114   gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCROLLBAR_ACCESSIBLE);
115 }
116
117 static void
118 gtk_scrollbar_init (GtkScrollbar *scrollbar)
119 {
120   GtkStyleContext *context;
121
122   context = gtk_widget_get_style_context (GTK_WIDGET (scrollbar));
123   gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCROLLBAR);
124 }
125
126 static void
127 gtk_scrollbar_style_updated (GtkWidget *widget)
128 {
129   GtkRange *range = GTK_RANGE (widget);
130   gint slider_length;
131   gboolean fixed_size;
132   gboolean has_a, has_b, has_c, has_d;
133
134   gtk_widget_style_get (widget,
135                         "min-slider-length", &slider_length,
136                         "fixed-slider-length", &fixed_size,
137                         "has-backward-stepper", &has_a,
138                         "has-secondary-forward-stepper", &has_b,
139                         "has-secondary-backward-stepper", &has_c,
140                         "has-forward-stepper", &has_d,
141                         NULL);
142
143   gtk_range_set_min_slider_size (range, slider_length);
144   gtk_range_set_slider_size_fixed (range, fixed_size);
145   _gtk_range_set_steppers (range,
146                            has_a, has_b, has_c, has_d);
147
148   GTK_WIDGET_CLASS (gtk_scrollbar_parent_class)->style_updated (widget);
149 }
150
151 /**
152  * gtk_scrollbar_new:
153  * @orientation: the scrollbar's orientation.
154  * @adjustment: (allow-none): the #GtkAdjustment to use, or %NULL to create a new adjustment.
155  *
156  * Creates a new scrollbar with the given orientation.
157  *
158  * Return value:  the new #GtkScrollbar.
159  *
160  * Since: 3.0
161  **/
162 GtkWidget *
163 gtk_scrollbar_new (GtkOrientation  orientation,
164                    GtkAdjustment  *adjustment)
165 {
166   g_return_val_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment),
167                         NULL);
168
169   return g_object_new (GTK_TYPE_SCROLLBAR,
170                        "orientation", orientation,
171                        "adjustment",  adjustment,
172                        NULL);
173 }