]> Pileus Git - ~andy/gtk/blob - gtk/gtkscrollbar.c
stylecontext: Do invalidation on first resize container
[~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, see <http://www.gnu.org/licenses/>.
17  */
18
19 /*
20  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
21  * file for a list of people on the GTK+ Team.  See the ChangeLog
22  * files for a list of changes.  These files are distributed with
23  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
24  */
25
26 #include "config.h"
27
28 #include "gtkscrollbar.h"
29
30 #include "gtkadjustment.h"
31 #include "gtkintl.h"
32 #include "gtkprivate.h"
33
34
35 /**
36  * SECTION:gtkscrollbar
37  * @Short_description: A Scrollbar
38  * @Title: GtkScrollbar
39  * @See_also: #GtkAdjustment, #GtkScrolledWindow
40  *
41  * The #GtkScrollbar widget is a horizontal or vertical scrollbar,
42  * depending on the value of the #GtkOrientable:orientation property.
43  *
44  * The position of the thumb in a scrollbar is controlled by the scroll
45  * adjustments. See #GtkAdjustment for the fields in an adjustment - for
46  * #GtkScrollbar, the #GtkAdjustment:value field represents the position
47  * of the scrollbar, which must be between the #GtkAdjustment:lower field
48  * and #GtkAdjustment:upper - #GtkAdjustment:page-size. The
49  * #GtkAdjustment:page-size field represents the size of the visible
50  * scrollable area. The #GtkAdjustment:step-increment and
51  * #GtkAdjustment:page-increment fields are properties when the user asks to
52  * step down (using the small stepper arrows) or page down (using for
53  * example the <keycap>PageDown</keycap> key).
54  */
55
56
57 static void gtk_scrollbar_style_updated (GtkWidget *widget);
58
59 G_DEFINE_TYPE (GtkScrollbar, gtk_scrollbar, GTK_TYPE_RANGE)
60
61 static void
62 gtk_scrollbar_class_init (GtkScrollbarClass *class)
63 {
64   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
65
66   widget_class->style_updated = gtk_scrollbar_style_updated;
67
68   gtk_widget_class_install_style_property (widget_class,
69                                            g_param_spec_int ("min-slider-length",
70                                                              P_("Minimum Slider Length"),
71                                                              P_("Minimum length of scrollbar slider"),
72                                                              0,
73                                                              G_MAXINT,
74                                                              21,
75                                                              GTK_PARAM_READABLE));
76
77   gtk_widget_class_install_style_property (widget_class,
78                                            g_param_spec_boolean ("fixed-slider-length",
79                                                                  P_("Fixed slider size"),
80                                                                  P_("Don't change slider size, just lock it to the minimum length"),
81                                                                  FALSE,
82                                                                  GTK_PARAM_READABLE));
83
84   gtk_widget_class_install_style_property (widget_class,
85                                            g_param_spec_boolean ("has-backward-stepper",
86                                                                  P_("Backward stepper"),
87                                                                  P_("Display the standard backward arrow button"),
88                                                                  TRUE,
89                                                                  GTK_PARAM_READABLE));
90
91   gtk_widget_class_install_style_property (widget_class,
92                                            g_param_spec_boolean ("has-forward-stepper",
93                                                                  P_("Forward stepper"),
94                                                                  P_("Display the standard forward arrow button"),
95                                                                  TRUE,
96                                                                  GTK_PARAM_READABLE));
97
98   gtk_widget_class_install_style_property (widget_class,
99                                            g_param_spec_boolean ("has-secondary-backward-stepper",
100                                                                  P_("Secondary backward stepper"),
101                                                                  P_("Display a second backward arrow button on the opposite end of the scrollbar"),
102                                                                  FALSE,
103                                                                  GTK_PARAM_READABLE));
104
105   gtk_widget_class_install_style_property (widget_class,
106                                            g_param_spec_boolean ("has-secondary-forward-stepper",
107                                                                  P_("Secondary forward stepper"),
108                                                                  P_("Display a second forward arrow button on the opposite end of the scrollbar"),
109                                                                  FALSE,
110                                                                  GTK_PARAM_READABLE));
111
112   gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_SCROLL_BAR);
113 }
114
115 static void
116 gtk_scrollbar_update_style (GtkScrollbar *scrollbar)
117 {
118   gint slider_length;
119   gboolean fixed_size;
120   gboolean has_a, has_b, has_c, has_d;
121   GtkRange *range = GTK_RANGE (scrollbar);
122   GtkWidget *widget = GTK_WIDGET (scrollbar);
123
124   gtk_widget_style_get (widget,
125                         "min-slider-length", &slider_length,
126                         "fixed-slider-length", &fixed_size,
127                         "has-backward-stepper", &has_a,
128                         "has-secondary-forward-stepper", &has_b,
129                         "has-secondary-backward-stepper", &has_c,
130                         "has-forward-stepper", &has_d,
131                         NULL);
132
133   gtk_range_set_min_slider_size (range, slider_length);
134   gtk_range_set_slider_size_fixed (range, fixed_size);
135   _gtk_range_set_steppers (range,
136                            has_a, has_b, has_c, has_d);
137 }
138
139 static void
140 gtk_scrollbar_init (GtkScrollbar *scrollbar)
141 {
142   GtkStyleContext *context;
143
144   context = gtk_widget_get_style_context (GTK_WIDGET (scrollbar));
145   gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCROLLBAR);
146   gtk_scrollbar_update_style (scrollbar);
147 }
148
149 static void
150 gtk_scrollbar_style_updated (GtkWidget *widget)
151 {
152   gtk_scrollbar_update_style (GTK_SCROLLBAR (widget));
153   GTK_WIDGET_CLASS (gtk_scrollbar_parent_class)->style_updated (widget);
154 }
155
156 /**
157  * gtk_scrollbar_new:
158  * @orientation: the scrollbar's orientation.
159  * @adjustment: (allow-none): the #GtkAdjustment to use, or %NULL to create a new adjustment.
160  *
161  * Creates a new scrollbar with the given orientation.
162  *
163  * Return value:  the new #GtkScrollbar.
164  *
165  * Since: 3.0
166  **/
167 GtkWidget *
168 gtk_scrollbar_new (GtkOrientation  orientation,
169                    GtkAdjustment  *adjustment)
170 {
171   g_return_val_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment),
172                         NULL);
173
174   return g_object_new (GTK_TYPE_SCROLLBAR,
175                        "orientation", orientation,
176                        "adjustment",  adjustment,
177                        NULL);
178 }