gtkscrollbar.c 7.08 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
16 17 18
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
19
 */
20 21

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

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

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

/**
 * SECTION:gtkscrollbar
 * @Short_description: Base class for GtkHScrollbar and GtkVScrollbar
 * @Title: GtkScrollbar
 * @See_also: #GtkHScrollbar, #GtkVScrollbar, #GtkAdjustment,
 *   #GtkScrolledWindow
 *
 * The #GtkScrollbar widget is the base class for #GtkHScrollbar and
 * #GtkVScrollbar. It can be used in the same way as these, by setting
 * the "orientation" property appropriately.
 *
 * The position of the thumb in a scrollbar is controlled by the scroll
 * adjustments. See #GtkAdjustment for the fields in an adjustment - for
 * #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 used when the user asks to
 * step down (using the small stepper arrows) or page down (using for
 * example the <keycap>PageDown</keycap> key).
 */


59 60
static void gtk_scrollbar_style_set (GtkWidget *widget,
                                     GtkStyle  *previous);
61

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

static void
gtk_scrollbar_class_init (GtkScrollbarClass *class)
{
67
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
68 69

  widget_class->style_set = gtk_scrollbar_style_set;
70

71 72
  GTK_RANGE_CLASS (class)->stepper_detail = "Xscrollbar";

73
  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
74
					   g_param_spec_int ("min-slider-length",
75 76
							     P_("Minimum Slider Length"),
							     P_("Minimum length of scrollbar slider"),
77 78
							     0,
							     G_MAXINT,
79
							     21,
80
							     GTK_PARAM_READABLE));
81 82

  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
83
					   g_param_spec_boolean ("fixed-slider-length",
84 85
                                                                 P_("Fixed slider size"),
                                                                 P_("Don't change slider size, just lock it to the minimum length"),
86
                                                                 FALSE,
87
                                                                 GTK_PARAM_READABLE));
88

89
  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
90
					   g_param_spec_boolean ("has-backward-stepper",
91 92
                                                                 P_("Backward stepper"),
                                                                 P_("Display the standard backward arrow button"),
93
                                                                 TRUE,
94
                                                                 GTK_PARAM_READABLE));
95

96 97 98 99 100 101
  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));
102 103

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

110 111 112 113 114 115
  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));
Elliot Lee's avatar
Elliot Lee committed
116 117 118 119 120
}

static void
gtk_scrollbar_init (GtkScrollbar *scrollbar)
{
121 122 123
}

static void
124 125
gtk_scrollbar_style_set (GtkWidget *widget,
                         GtkStyle  *previous)
126
{
127
  GtkRange *range = GTK_RANGE (widget);
128 129 130 131 132
  gint slider_length;
  gboolean fixed_size;
  gboolean has_a, has_b, has_c, has_d;

  gtk_widget_style_get (widget,
133 134 135 136 137 138
                        "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,
139
                        NULL);
140

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

  GTK_WIDGET_CLASS (gtk_scrollbar_parent_class)->style_set (widget, previous);
Elliot Lee's avatar
Elliot Lee committed
147
}
148

149 150 151
/**
 * gtk_scrollbar_new:
 * @orientation: the scrollbar's orientation.
Johan Dahlin's avatar
Johan Dahlin committed
152
 * @adjustment: (allow-none): the #GtkAdjustment to use, or %NULL to create a new adjustment.
153 154 155 156 157
 *
 * Creates a new scrollbar with the given orientation.
 *
 * Return value:  the new #GtkScrollbar.
 *
158
 * Since: 3.0
159 160 161 162 163 164 165 166 167 168 169 170 171
 **/
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);
}