2 * Copyright (C) 2008 Tadej Borovšak <tadeboro@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * SECTION:gtkscrollable
20 * @Short_Description: An interface for scrollable widgets
21 * @Title: GtkScrollable
23 * #GtkScrollable is an interface that is implemented by widgets with native
26 * To implement this interface you should override the
27 * #GtkScrollable:hadjustment and #GtkScrollable:vadjustment properties.
30 * <title>Creating a scrollable widget</title>
32 * All scrollable widgets should do the following.
37 * When a parent widget sets the scrollable child widget's adjustments, the widget should populate the adjustments'
38 * #GtkAdjustment:lower, #GtkAdjustment:upper,
39 * #GtkAdjustment:step-increment, #GtkAdjustment:page-increment and
40 * #GtkAdjustment:page-size properties and connect to the
41 * #GtkAdjustment::value-changed signal.
46 * Because its preferred size is the size for a fully expanded widget,
47 * the scrollable widget must be able to cope with underallocations.
48 * This means that it must accept any value passed to its
49 * #GtkWidgetClass.size_allocate() function.
54 * When the parent allocates space to the scrollable child widget, the widget should update
55 * the adjustments' properties with new values.
60 * When any of the adjustments emits the #GtkAdjustment::value-changed signal,
61 * the scrollable widget should scroll its contents.
71 #include "gtkscrollable.h"
72 #include "gtkprivate.h"
73 #include "gtktypebuiltins.h"
76 G_DEFINE_INTERFACE (GtkScrollable, gtk_scrollable, G_TYPE_OBJECT)
79 gtk_scrollable_default_init (GtkScrollableInterface *iface)
84 * GtkScrollable:hadjustment:
86 * Horizontal #GtkAdjustment of the scrollable widget. This adjustment is
87 * shared between the scrollable widget and its parent.
91 pspec = g_param_spec_object ("hadjustment",
92 P_("Horizontal adjustment"),
93 P_("Horizontal adjustment that is shared "
94 "between the scrollable widget and its "
97 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT);
98 g_object_interface_install_property (iface, pspec);
101 * GtkScrollable:vadjustment:
103 * Verical #GtkAdjustment of the scrollable widget. This adjustment is shared
104 * between the scrollable widget and its parent.
108 pspec = g_param_spec_object ("vadjustment",
109 P_("Vertical adjustment"),
110 P_("Vertical adjustment that is shared "
111 "between the scrollable widget and its "
114 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT);
115 g_object_interface_install_property (iface, pspec);
118 * GtkScrollable:hscroll-policy:
120 * Determines whether horizontal scrolling should start once the scrollable
121 * widget is allocated less than its minimum width or less than its natural width.
125 pspec = g_param_spec_enum ("hscroll-policy",
126 P_("Horizontal Scrollable Policy"),
127 P_("How the size of the content should be determined"),
128 GTK_TYPE_SCROLLABLE_POLICY,
130 GTK_PARAM_READWRITE);
131 g_object_interface_install_property (iface, pspec);
134 * GtkScrollable:vscroll-policy:
136 * Determines whether vertical scrolling should start once the scrollable
137 * widget is allocated less than its minimum height or less than its natural height.
141 pspec = g_param_spec_enum ("vscroll-policy",
142 P_("Vertical Scrollable Policy"),
143 P_("How the size of the content should be determined"),
144 GTK_TYPE_SCROLLABLE_POLICY,
146 GTK_PARAM_READWRITE);
147 g_object_interface_install_property (iface, pspec);
151 * gtk_scrollable_get_hadjustment:
152 * @scrollable: a #GtkScrollable
154 * Retrieves the #GtkAdjustment used for horizontal scrolling.
156 * Return value: (transfer none): horizontal #GtkAdjustment.
161 gtk_scrollable_get_hadjustment (GtkScrollable *scrollable)
163 GtkAdjustment *adj = NULL;
165 g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), NULL);
167 g_object_get (scrollable, "hadjustment", &adj, NULL);
169 /* Horrid hack; g_object_get() returns a new reference but
170 * that contradicts the memory management conventions
174 g_object_unref (adj);
180 * gtk_scrollable_set_hadjustment:
181 * @scrollable: a #GtkScrollable
182 * @hadjustment: (allow-none): a #GtkAdjustment
184 * Sets the horizontal adjustment of the #GtkScrollable.
189 gtk_scrollable_set_hadjustment (GtkScrollable *scrollable,
190 GtkAdjustment *hadjustment)
192 g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
193 g_return_if_fail (hadjustment == NULL || GTK_IS_ADJUSTMENT (hadjustment));
195 g_object_set (scrollable, "hadjustment", hadjustment, NULL);
199 * gtk_scrollable_get_vadjustment:
200 * @scrollable: a #GtkScrollable
202 * Retrieves the #GtkAdjustment used for vertical scrolling.
204 * Return value: (transfer none): vertical #GtkAdjustment.
209 gtk_scrollable_get_vadjustment (GtkScrollable *scrollable)
211 GtkAdjustment *adj = NULL;
213 g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), NULL);
215 g_object_get (scrollable, "vadjustment", &adj, NULL);
217 /* Horrid hack; g_object_get() returns a new reference but
218 * that contradicts the memory management conventions
222 g_object_unref (adj);
228 * gtk_scrollable_set_vadjustment:
229 * @scrollable: a #GtkScrollable
230 * @vadjustment: (allow-none): a #GtkAdjustment
232 * Sets the vertical adjustment of the #GtkScrollable.
237 gtk_scrollable_set_vadjustment (GtkScrollable *scrollable,
238 GtkAdjustment *vadjustment)
240 g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
241 g_return_if_fail (vadjustment == NULL || GTK_IS_ADJUSTMENT (vadjustment));
243 g_object_set (scrollable, "vadjustment", vadjustment, NULL);
248 * gtk_scrollable_get_hscroll_policy:
249 * @scrollable: a #GtkScrollable
251 * Gets the horizontal #GtkScrollablePolicy.
253 * Return value: The horizontal #GtkScrollablePolicy.
258 gtk_scrollable_get_hscroll_policy (GtkScrollable *scrollable)
260 GtkScrollablePolicy policy;
262 g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), GTK_SCROLL_MINIMUM);
264 g_object_get (scrollable, "hscroll-policy", &policy, NULL);
270 * gtk_scrollable_set_hscroll_policy:
271 * @scrollable: a #GtkScrollable
272 * @policy: the horizontal #GtkScrollablePolicy
274 * Sets the #GtkScrollablePolicy to determine whether
275 * horizontal scrolling should start below the minimum width or
276 * below the natural width.
281 gtk_scrollable_set_hscroll_policy (GtkScrollable *scrollable,
282 GtkScrollablePolicy policy)
284 g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
286 g_object_set (scrollable, "hscroll-policy", policy, NULL);
290 * gtk_scrollable_get_vscroll_policy:
291 * @scrollable: a #GtkScrollable
293 * Gets the vertical #GtkScrollablePolicy.
295 * Return value: The vertical #GtkScrollablePolicy.
300 gtk_scrollable_get_vscroll_policy (GtkScrollable *scrollable)
302 GtkScrollablePolicy policy;
304 g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), GTK_SCROLL_MINIMUM);
306 g_object_get (scrollable, "vscroll-policy", &policy, NULL);
312 * gtk_scrollable_set_vscroll_policy:
313 * @scrollable: a #GtkScrollable
314 * @policy: the vertical #GtkScrollablePolicy
316 * Sets the #GtkScrollablePolicy to determine whether
317 * vertical scrolling should start below the minimum height or
318 * below the natural height.
323 gtk_scrollable_set_vscroll_policy (GtkScrollable *scrollable,
324 GtkScrollablePolicy policy)
326 g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
328 g_object_set (scrollable, "vscroll-policy", policy, NULL);