1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 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
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* CTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 * Copyright (C) 2001 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * Modified by the CTK+ Team and others 1997-2000.  See the AUTHORS
 * file for a list of people on the CTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * CTK+ at ftp://ftp.ctk.org/pub/ctk/.
 */

#include "config.h"

#include "ctkscrollbar.h"
#include "ctkrangeprivate.h"

#include "ctkadjustment.h"
#include "ctkintl.h"
#include "ctkorientable.h"
#include "ctkprivate.h"


/**
 * SECTION:ctkscrollbar
 * @Short_description: A Scrollbar
 * @Title: CtkScrollbar
 * @See_also: #CtkAdjustment, #CtkScrolledWindow
 *
 * The #CtkScrollbar widget is a horizontal or vertical scrollbar,
 * depending on the value of the #CtkOrientable:orientation property.
 *
 * Its position and movement are controlled by the adjustment that is passed to
 * or created by ctk_scrollbar_new(). See #CtkAdjustment for more details. The
 * #CtkAdjustment:value field sets the position of the thumb and must be between
 * #CtkAdjustment:lower and #CtkAdjustment:upper - #CtkAdjustment:page-size. The
 * #CtkAdjustment:page-size represents the size of the visible scrollable area.
 * The fields #CtkAdjustment:step-increment and #CtkAdjustment:page-increment
 * fields are added to or subtracted from the #CtkAdjustment:value when the user
 * asks to move by a step (using e.g. the cursor arrow keys or, if present, the
 * stepper buttons) or by a page (using e.g. the Page Down/Up keys).
 *
 * # CSS nodes
 *
 * |[<!-- language="plain" -->
 * scrollbar[.fine-tune]
 * ╰── contents
 *     ├── [button.up]
 *     ├── [button.down]
 *     ├── trough
 *     │   ╰── slider
 *     ├── [button.up]
 *     ╰── [button.down]
 * ]|
 *
 * CtkScrollbar has a main CSS node with name scrollbar and a subnode for its
 * contents, with subnodes named trough and slider.
 *
 * The main node gets the style class .fine-tune added when the scrollbar is
 * in 'fine-tuning' mode.
 *
 * If steppers are enabled, they are represented by up to four additional
 * subnodes with name button. These get the style classes .up and .down to
 * indicate in which direction they are moving.
 *
 * Other style classes that may be added to scrollbars inside #CtkScrolledWindow
 * include the positional classes (.left, .right, .top, .bottom) and style
 * classes related to overlay scrolling (.overlay-indicator, .dragging, .hovering).
 */


static void ctk_scrollbar_style_updated (CtkWidget *widget);

G_DEFINE_TYPE (CtkScrollbar, ctk_scrollbar, CTK_TYPE_RANGE)<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE is a macro then please configure it.

static void
ctk_scrollbar_class_init (CtkScrollbarClass *class)
{
  CtkWidgetClass *widget_class = CTK_WIDGET_CLASS (class);

  widget_class->style_updated = ctk_scrollbar_style_updated;

  /**
   * CtkScrollbar:min-slider-length:
   *
   * Minimum length of scrollbar slider.
   *
   * Deprecated: 3.20: Use min-height/min-width CSS properties on the slider
   *   element instead. The value of this style property is ignored.
   */
  ctk_widget_class_install_style_property (widget_class,
					   g_param_spec_int ("min-slider-length",
							     P_("Minimum Slider Length"),
							     P_("Minimum length of scrollbar slider"),
							     0,
							     G_MAXINT,
							     21,
							     CTK_PARAM_READABLE|G_PARAM_DEPRECATED));

  ctk_widget_class_install_style_property (widget_class,
					   g_param_spec_boolean ("fixed-slider-length",
                                                                 P_("Fixed slider size"),
                                                                 P_("Don't change slider size, just lock it to the minimum length"),
                                                                 FALSE,
                                                                 CTK_PARAM_READABLE));

  ctk_widget_class_install_style_property (widget_class,
					   g_param_spec_boolean ("has-backward-stepper",
                                                                 P_("Backward stepper"),
                                                                 P_("Display the standard backward arrow button"),
                                                                 TRUE,
                                                                 CTK_PARAM_READABLE));

  ctk_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,
                                                                 CTK_PARAM_READABLE));

  ctk_widget_class_install_style_property (widget_class,
					   g_param_spec_boolean ("has-secondary-backward-stepper",
                                                                 P_("Secondary backward stepper"),
                                                                 P_("Display a second backward arrow button on the opposite end of the scrollbar"),
                                                                 FALSE,
                                                                 CTK_PARAM_READABLE));

  ctk_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,
                                                                 CTK_PARAM_READABLE));

  ctk_widget_class_set_accessible_role (widget_class, ATK_ROLE_SCROLL_BAR);
  ctk_widget_class_set_css_name (widget_class, "scrollbar");
}

static void
ctk_scrollbar_update_style (CtkScrollbar *scrollbar)
{
  gboolean fixed_size;
  gboolean has_a, has_b, has_c, has_d;
  CtkRange *range = CTK_RANGE (scrollbar);
  CtkWidget *widget = CTK_WIDGET (scrollbar);

  ctk_widget_style_get (widget,
                        "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,
                        NULL);

  ctk_range_set_slider_size_fixed (range, fixed_size);
  _ctk_range_set_steppers (range, has_a, has_b, has_c, has_d);
}

static void
ctk_scrollbar_init (CtkScrollbar *scrollbar)
{
  ctk_scrollbar_update_style (scrollbar);
  ctk_range_set_slider_use_min_size (CTK_RANGE (scrollbar), TRUE);
}

static void
ctk_scrollbar_style_updated (CtkWidget *widget)
{
  ctk_scrollbar_update_style (CTK_SCROLLBAR (widget));
  CTK_WIDGET_CLASS (ctk_scrollbar_parent_class)->style_updated (widget);
}

/**
 * ctk_scrollbar_new:
 * @orientation: the scrollbar’s orientation.
 * @adjustment: (allow-none): the #CtkAdjustment to use, or %NULL to create a new adjustment.
 *
 * Creates a new scrollbar with the given orientation.
 *
 * Returns:  the new #CtkScrollbar.
 *
 * Since: 3.0
 **/
CtkWidget *
ctk_scrollbar_new (CtkOrientation  orientation,
                   CtkAdjustment  *adjustment)
{
  g_return_val_if_fail (adjustment == NULL || CTK_IS_ADJUSTMENT (adjustment),
                        NULL);

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