]> Pileus Git - ~andy/gtk/blob - gtk/gtkscrollbar.c
Use accessor functions to access GtkRange
[~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 static void gtk_scrollbar_style_set (GtkWidget *widget,
35                                      GtkStyle  *previous);
36
37 G_DEFINE_TYPE (GtkScrollbar, gtk_scrollbar, GTK_TYPE_RANGE)
38
39 static void
40 gtk_scrollbar_class_init (GtkScrollbarClass *class)
41 {
42   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
43
44   widget_class->style_set = gtk_scrollbar_style_set;
45
46   GTK_RANGE_CLASS (class)->stepper_detail = "Xscrollbar";
47
48   gtk_widget_class_install_style_property (widget_class,
49                                            g_param_spec_int ("min-slider-length",
50                                                              P_("Minimum Slider Length"),
51                                                              P_("Minimum length of scrollbar slider"),
52                                                              0,
53                                                              G_MAXINT,
54                                                              21,
55                                                              GTK_PARAM_READABLE));
56
57   gtk_widget_class_install_style_property (widget_class,
58                                            g_param_spec_boolean ("fixed-slider-length",
59                                                                  P_("Fixed slider size"),
60                                                                  P_("Don't change slider size, just lock it to the minimum length"),
61                                                                  FALSE,
62                                                                  GTK_PARAM_READABLE));
63
64   gtk_widget_class_install_style_property (widget_class,
65                                            g_param_spec_boolean ("has-backward-stepper",
66                                                                  P_("Backward stepper"),
67                                                                  P_("Display the standard backward arrow button"),
68                                                                  TRUE,
69                                                                  GTK_PARAM_READABLE));
70
71   gtk_widget_class_install_style_property (widget_class,
72                                            g_param_spec_boolean ("has-forward-stepper",
73                                                                  P_("Forward stepper"),
74                                                                  P_("Display the standard forward arrow button"),
75                                                                  TRUE,
76                                                                  GTK_PARAM_READABLE));
77
78   gtk_widget_class_install_style_property (widget_class,
79                                            g_param_spec_boolean ("has-secondary-backward-stepper",
80                                                                  P_("Secondary backward stepper"),
81                                                                  P_("Display a second backward arrow button on the opposite end of the scrollbar"),
82                                                                  FALSE,
83                                                                  GTK_PARAM_READABLE));
84
85   gtk_widget_class_install_style_property (widget_class,
86                                            g_param_spec_boolean ("has-secondary-forward-stepper",
87                                                                  P_("Secondary forward stepper"),
88                                                                  P_("Display a second forward arrow button on the opposite end of the scrollbar"),
89                                                                  FALSE,
90                                                                  GTK_PARAM_READABLE));
91 }
92
93 static void
94 gtk_scrollbar_init (GtkScrollbar *scrollbar)
95 {
96 }
97
98 static void
99 gtk_scrollbar_style_set (GtkWidget *widget,
100                          GtkStyle  *previous)
101 {
102   GtkRange *range = GTK_RANGE (widget);
103   gint slider_length;
104   gboolean fixed_size;
105   gboolean has_a, has_b, has_c, has_d;
106
107   gtk_widget_style_get (widget,
108                         "min-slider-length", &slider_length,
109                         "fixed-slider-length", &fixed_size,
110                         "has-backward-stepper", &has_a,
111                         "has-secondary-forward-stepper", &has_b,
112                         "has-secondary-backward-stepper", &has_c,
113                         "has-forward-stepper", &has_d,
114                         NULL);
115
116   gtk_range_set_min_slider_size (range, slider_length);
117   gtk_range_set_slider_size_fixed (range, fixed_size);
118   _gtk_range_set_steppers (range,
119                            has_a, has_b, has_c, has_d);
120
121   GTK_WIDGET_CLASS (gtk_scrollbar_parent_class)->style_set (widget, previous);
122 }
123
124 /**
125  * gtk_scrollbar_new:
126  * @orientation: the scrollbar's orientation.
127  * @adjustment: (allow-none): the #GtkAdjustment to use, or %NULL to create a new adjustment.
128  *
129  * Creates a new scrollbar with the given orientation.
130  *
131  * Return value:  the new #GtkScrollbar.
132  *
133  * Since: 3.0
134  **/
135 GtkWidget *
136 gtk_scrollbar_new (GtkOrientation  orientation,
137                    GtkAdjustment  *adjustment)
138 {
139   g_return_val_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment),
140                         NULL);
141
142   return g_object_new (GTK_TYPE_SCROLLBAR,
143                        "orientation", orientation,
144                        "adjustment",  adjustment,
145                        NULL);
146 }