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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * SECTION:gtkscrollable
22 * @Short_Description: An interface for scrollable widgets
23 * @Title: GtkScrollable
25 * #GtkScrollable is interface that is implemented by widgets with native
28 * To implement this interface, all one needs to do is to override
29 * #GtkScrollable:hadjustment and #GtkScrollable:vadjustment properties.
32 * <title>Creating a scrollable widget</title>
34 * There are some common things all scrollable widgets will need to do.
39 * When parent sets adjustments, widget needs to populate adjustment's
40 * #GtkAdjustment:lower, #GtkAdjustment:upper,
41 * #GtkAdjustment:step-increment, #GtkAdjustment:page-increment and
42 * #GtkAdjustment:page-size properties and connect to
43 * #GtkAdjustment::value-changed signal.
48 * When parent allocates space to child, scrollable widget needs to update
49 * properties listed under 1 with new values.
54 * When any of the adjustments emits #GtkAdjustment::value-changed signal,
55 * scrollable widget needs to scroll it's contents.
65 #include "gtkscrollable.h"
66 #include "gtkprivate.h"
69 G_DEFINE_INTERFACE (GtkScrollable, gtk_scrollable, G_TYPE_OBJECT)
72 gtk_scrollable_default_init (GtkScrollableInterface *iface)
77 * GtkScrollable:hadjustment:
79 * Horizontal #GtkAdjustment of scrollable widget. This adjustment is
80 * shared between scrollable widget and it's parent.
84 pspec = g_param_spec_object ("hadjustment",
85 P_("Horizontal adjustment"),
86 P_("Horizontal adjustment that is shared "
87 "between scrollable widget and it's "
90 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT);
91 g_object_interface_install_property (iface, pspec);
94 * GtkScrollable:vadjustment:
96 * Verical #GtkAdjustment of scrollable widget. This adjustment is shared
97 * between scrollable widget and it's parent.
101 pspec = g_param_spec_object ("vadjustment",
102 P_("Vertical adjustment"),
103 P_("Vertical adjustment that is shared "
104 "between scrollable widget and it's "
107 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT);
108 g_object_interface_install_property (iface, pspec);
112 * GtkScrollable:min-display-width:
114 * Minimum width to display in the parent scrolled window, this
115 * can be greater or less than the scrollable widget's real minimum
120 pspec = g_param_spec_int ("min-display-width",
121 P_("Minimum Display Width"),
122 P_("Minimum width to display in the parent scrolled window"),
124 GTK_PARAM_READWRITE);
125 g_object_interface_install_property (iface, pspec);
129 * GtkScrollable:min-display-height:
131 * Minimum height to display in the parent scrolled window, this
132 * can be greater or less than the scrollable widget's real minimum
137 pspec = g_param_spec_int ("min-display-height",
138 P_("Minimum Display Height"),
139 P_("Minimum height to display in the parent scrolled window"),
141 GTK_PARAM_READWRITE);
142 g_object_interface_install_property (iface, pspec);
147 * gtk_scrollable_get_hadjustment:
148 * @scrollable: a #GtkScrollable
150 * Retrieves the #GtkAdjustment, used for horizontal scrolling.
152 * Return value: (transfer none): horizontal #GtkAdjustment.
157 gtk_scrollable_get_hadjustment (GtkScrollable *scrollable)
159 GtkAdjustment *adj = NULL;
161 g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), NULL);
163 g_object_get (scrollable, "hadjustment", &adj, NULL);
165 /* Horrid hack; g_object_get() returns a new reference but
166 * that contradicts the memory management conventions
170 g_object_unref (adj);
176 * gtk_scrollable_set_hadjustment:
177 * @scrollable: a #GtkScrollable
178 * @hadjustment: (allow-none): a #GtkAdjustment
180 * Sets the horizontal adjustment of the #GtkScrollable.
185 gtk_scrollable_set_hadjustment (GtkScrollable *scrollable,
186 GtkAdjustment *hadjustment)
188 g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
189 g_return_if_fail (hadjustment == NULL || GTK_IS_ADJUSTMENT (hadjustment));
191 g_object_set (scrollable, "hadjustment", hadjustment, NULL);
195 * gtk_scrollable_get_vadjustment:
196 * @scrollable: a #GtkScrollable
198 * Retrieves the #GtkAdjustment, used for vertical scrolling.
200 * Return value: (transfer none): vertical #GtkAdjustment.
205 gtk_scrollable_get_vadjustment (GtkScrollable *scrollable)
207 GtkAdjustment *adj = NULL;
209 g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), NULL);
211 g_object_get (scrollable, "vadjustment", &adj, NULL);
213 /* Horrid hack; g_object_get() returns a new reference but
214 * that contradicts the memory management conventions
218 g_object_unref (adj);
224 * gtk_scrollable_set_vadjustment:
225 * @scrollable: a #GtkScrollable
226 * @vadjustment: (allow-none): a #GtkAdjustment
228 * Sets the vertical adjustment of the #GtkScrollable.
233 gtk_scrollable_set_vadjustment (GtkScrollable *scrollable,
234 GtkAdjustment *vadjustment)
236 g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
237 g_return_if_fail (vadjustment == NULL || GTK_IS_ADJUSTMENT (vadjustment));
239 g_object_set (scrollable, "vadjustment", vadjustment, NULL);
244 * gtk_scrollable_get_min_display_width:
245 * @scrollable: a #GtkScrollable
247 * Retrieves the minimum width of content to display in the
248 * parent scrolled window.
250 * Return value: The minimum display width.
255 gtk_scrollable_get_min_display_width (GtkScrollable *scrollable)
259 g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), 0);
261 g_object_get (scrollable, "min-display-width", &width, NULL);
267 * gtk_scrollable_set_min_display_width:
268 * @scrollable: a #GtkScrollable
269 * @width: the minimum width of scrollable content to display
271 * Sets the minimum width of content to display in the parent scrolled window,
272 * this can be greater or less than the scrollable widget's real minimum
278 gtk_scrollable_set_min_display_width (GtkScrollable *scrollable,
281 g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
283 g_object_set (scrollable, "min-display-width", width, NULL);
287 * gtk_scrollable_get_min_display_height:
288 * @scrollable: a #GtkScrollable
290 * Retrieves the minimum height of content to display in the
291 * parent scrolled window.
293 * Return value: The minimum display height.
298 gtk_scrollable_get_min_display_height (GtkScrollable *scrollable)
302 g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), 0);
304 g_object_get (scrollable, "min-display-height", &height, NULL);
310 * gtk_scrollable_set_min_display_height:
311 * @scrollable: a #GtkScrollable
312 * @height: the minimum height of scrollable content to display
314 * Sets the minimum height of content to display in the parent scrolled window,
315 * this can be greater or less than the scrollable widget's real minimum
321 gtk_scrollable_set_min_display_height (GtkScrollable *scrollable,
324 g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
326 g_object_set (scrollable, "min-display-height", height, NULL);