gtkscrollbar.c 7.06 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
Elliot Lee's avatar
Elliot Lee committed
2
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3
 * Copyright (C) 2001 Red Hat, Inc.
Elliot Lee's avatar
Elliot Lee committed
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
Elliot Lee's avatar
Elliot Lee committed
7 8 9 10 11 12
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
Javier Jardón's avatar
Javier Jardón committed
16
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
Elliot Lee's avatar
Elliot Lee committed
17
 */
18 19

/*
20
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
21 22
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * 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

Elliot Lee's avatar
Elliot Lee committed
28
#include "gtkscrollbar.h"
29 30

#include "gtkadjustment.h"
31
#include "gtkintl.h"
32
#include "gtkprivate.h"
Elliot Lee's avatar
Elliot Lee committed
33

34 35
#include "a11y/gtkscrollbaraccessible.h"

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 47
 *
 * The position of the thumb in a scrollbar is controlled by the scroll
 * adjustments. See #GtkAdjustment for the fields in an adjustment - for
48 49 50 51 52 53
 * #GtkScrollbar, the #GtkAdjustment:value field represents the position
 * of the scrollbar, which must be between the #GtkAdjustment:lower field
 * and #GtkAdjustment:upper - #GtkAdjustment:page-size. The
 * #GtkAdjustment:page-size field represents the size of the visible
 * scrollable area. The #GtkAdjustment:step-increment and
 * #GtkAdjustment:page-increment fields are properties when the user asks to
54 55 56 57 58
 * step down (using the small stepper arrows) or page down (using for
 * example the <keycap>PageDown</keycap> key).
 */


59
static void gtk_scrollbar_style_updated (GtkWidget *widget);
60

61
G_DEFINE_TYPE (GtkScrollbar, gtk_scrollbar, GTK_TYPE_RANGE)
Elliot Lee's avatar
Elliot Lee committed
62 63 64 65

static void
gtk_scrollbar_class_init (GtkScrollbarClass *class)
{
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,
Matthias Clasen's avatar
x  
Matthias Clasen committed
71
					   g_param_spec_int ("min-slider-length",
72 73
							     P_("Minimum Slider Length"),
							     P_("Minimum length of scrollbar slider"),
74 75
							     0,
							     G_MAXINT,
76
							     21,
77
							     GTK_PARAM_READABLE));
78 79

  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
80
					   g_param_spec_boolean ("fixed-slider-length",
81 82
                                                                 P_("Fixed slider size"),
                                                                 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,
Matthias Clasen's avatar
x  
Matthias Clasen committed
87
					   g_param_spec_boolean ("has-backward-stepper",
88 89
                                                                 P_("Backward stepper"),
                                                                 P_("Display the standard backward arrow button"),
90
                                                                 TRUE,
91
                                                                 GTK_PARAM_READABLE));
92

93 94 95 96 97 98
  gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_boolean ("has-forward-stepper",
                                                                 P_("Forward stepper"),
                                                                 P_("Display the standard forward arrow button"),
                                                                 TRUE,
                                                                 GTK_PARAM_READABLE));
99 100

  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
101
					   g_param_spec_boolean ("has-secondary-backward-stepper",
102 103
                                                                 P_("Secondary backward stepper"),
                                                                 P_("Display a second backward arrow button on the opposite end of the scrollbar"),
104
                                                                 FALSE,
105
                                                                 GTK_PARAM_READABLE));
106

107 108 109 110 111 112
  gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_boolean ("has-secondary-forward-stepper",
                                                                 P_("Secondary forward stepper"),
                                                                 P_("Display a second forward arrow button on the opposite end of the scrollbar"),
                                                                 FALSE,
                                                                 GTK_PARAM_READABLE));
113 114

  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCROLLBAR_ACCESSIBLE);
Elliot Lee's avatar
Elliot Lee committed
115 116 117 118 119
}

static void
gtk_scrollbar_init (GtkScrollbar *scrollbar)
{
120 121 122 123
  GtkStyleContext *context;

  context = gtk_widget_get_style_context (GTK_WIDGET (scrollbar));
  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 131 132 133 134
  gint slider_length;
  gboolean fixed_size;
  gboolean has_a, has_b, has_c, has_d;

  gtk_widget_style_get (widget,
135 136 137 138 139 140
                        "min-slider-length", &slider_length,
                        "fixed-slider-length", &fixed_size,
                        "has-backward-stepper", &has_a,
                        "has-secondary-forward-stepper", &has_b,
                        "has-secondary-backward-stepper", &has_c,
                        "has-forward-stepper", &has_d,
141
                        NULL);
142

143 144
  gtk_range_set_min_slider_size (range, slider_length);
  gtk_range_set_slider_size_fixed (range, fixed_size);
145 146
  _gtk_range_set_steppers (range,
                           has_a, has_b, has_c, has_d);
147

148
  GTK_WIDGET_CLASS (gtk_scrollbar_parent_class)->style_updated (widget);
Elliot Lee's avatar
Elliot Lee committed
149
}
150

151 152 153
/**
 * gtk_scrollbar_new:
 * @orientation: the scrollbar's orientation.
154
 * @adjustment: (allow-none): the #GtkAdjustment to use, or %NULL to create a new adjustment.
155 156 157 158 159
 *
 * Creates a new scrollbar with the given orientation.
 *
 * Return value:  the new #GtkScrollbar.
 *
160
 * Since: 3.0
161 162 163 164 165 166 167 168 169 170 171 172 173
 **/
GtkWidget *
gtk_scrollbar_new (GtkOrientation  orientation,
                   GtkAdjustment  *adjustment)
{
  g_return_val_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment),
                        NULL);

  return g_object_new (GTK_TYPE_SCROLLBAR,
                       "orientation", orientation,
                       "adjustment",  adjustment,
                       NULL);
}