2010-10-18 04:21:39 +00:00
|
|
|
|
/* gtkscrollable.c
|
|
|
|
|
* Copyright (C) 2008 Tadej Borovšak <tadeboro@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* GtkScrollable:
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2021-03-01 06:46:15 +00:00
|
|
|
|
* `GtkScrollable` is an interface for widgets with native scrolling ability.
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2010-11-02 08:23:24 +00:00
|
|
|
|
* To implement this interface you should override the
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* [property@Gtk.Scrollable:hadjustment] and
|
|
|
|
|
* [property@Gtk.Scrollable:vadjustment] properties.
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2014-02-02 05:29:00 +00:00
|
|
|
|
* ## Creating a scrollable widget
|
|
|
|
|
*
|
2010-11-02 08:23:24 +00:00
|
|
|
|
* All scrollable widgets should do the following.
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* - When a parent widget sets the scrollable child widget’s adjustments,
|
2014-02-07 18:26:12 +00:00
|
|
|
|
* the widget should populate the adjustments’
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* [property@Gtk.Adjustment:lower],
|
|
|
|
|
* [property@Gtk.Adjustment:upper],
|
|
|
|
|
* [property@Gtk.Adjustment:step-increment],
|
|
|
|
|
* [property@Gtk.Adjustment:page-increment] and
|
|
|
|
|
* [property@Gtk.Adjustment:page-size] properties and connect to the
|
|
|
|
|
* [signal@Gtk.Adjustment::value-changed] signal.
|
2014-02-02 05:29:00 +00:00
|
|
|
|
*
|
|
|
|
|
* - Because its preferred size is the size for a fully expanded widget,
|
|
|
|
|
* the scrollable widget must be able to cope with underallocations.
|
|
|
|
|
* This means that it must accept any value passed to its
|
2021-05-18 21:05:26 +00:00
|
|
|
|
* [vfunc@Gtk.Widget.size_allocate] implementation.
|
2014-02-02 05:29:00 +00:00
|
|
|
|
*
|
|
|
|
|
* - When the parent allocates space to the scrollable child widget,
|
2014-02-07 18:26:12 +00:00
|
|
|
|
* the widget should update the adjustments’ properties with new values.
|
2014-02-02 05:29:00 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* - When any of the adjustments emits the [signal@Gtk.Adjustment::value-changed]
|
|
|
|
|
* signal, the scrollable widget should scroll its contents.
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include "gtkscrollable.h"
|
2012-03-03 18:41:55 +00:00
|
|
|
|
|
|
|
|
|
#include "gtkadjustment.h"
|
2010-10-18 04:21:39 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2011-01-04 17:05:05 +00:00
|
|
|
|
#include "gtktypebuiltins.h"
|
2010-10-18 04:21:39 +00:00
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
|
|
|
|
G_DEFINE_INTERFACE (GtkScrollable, gtk_scrollable, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_scrollable_default_init (GtkScrollableInterface *iface)
|
|
|
|
|
{
|
|
|
|
|
GParamSpec *pspec;
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* GtkScrollable:hadjustment: (attributes org.gtk.Property.get=gtk_scrollable_get_hadjustment org.gtk.Property.set=gtk_scrollable_set_hadjustment)
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Horizontal `GtkAdjustment` of the scrollable widget.
|
|
|
|
|
*
|
|
|
|
|
* This adjustment is shared between the scrollable widget and its parent.
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*/
|
|
|
|
|
pspec = g_param_spec_object ("hadjustment",
|
|
|
|
|
P_("Horizontal adjustment"),
|
|
|
|
|
P_("Horizontal adjustment that is shared "
|
2010-11-02 08:23:24 +00:00
|
|
|
|
"between the scrollable widget and its "
|
2010-10-18 04:21:39 +00:00
|
|
|
|
"controller"),
|
|
|
|
|
GTK_TYPE_ADJUSTMENT,
|
|
|
|
|
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT);
|
|
|
|
|
g_object_interface_install_property (iface, pspec);
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* GtkScrollable:vadjustment: (attributes org.gtk.Property.get=gtk_scrollable_get_vadjustment org.gtk.Property.set=gtk_scrollable_set_vadjustment)
|
|
|
|
|
*
|
|
|
|
|
* Vertical `GtkAdjustment` of the scrollable widget.
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* This adjustment is shared between the scrollable widget and its parent.
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*/
|
|
|
|
|
pspec = g_param_spec_object ("vadjustment",
|
|
|
|
|
P_("Vertical adjustment"),
|
|
|
|
|
P_("Vertical adjustment that is shared "
|
2010-11-02 08:23:24 +00:00
|
|
|
|
"between the scrollable widget and its "
|
2010-10-18 04:21:39 +00:00
|
|
|
|
"controller"),
|
|
|
|
|
GTK_TYPE_ADJUSTMENT,
|
|
|
|
|
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT);
|
|
|
|
|
g_object_interface_install_property (iface, pspec);
|
2010-10-26 00:59:02 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* GtkScrollable:hscroll-policy: (attributes org.gtk.Property.get=gtk_scrollable_get_hscroll_policy org.gtk.Property.set=gtk_scrollable_set_hscroll_policy)
|
2010-10-26 00:59:02 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Determines when horizontal scrolling should start.
|
2010-10-26 00:59:02 +00:00
|
|
|
|
*/
|
|
|
|
|
pspec = g_param_spec_enum ("hscroll-policy",
|
|
|
|
|
P_("Horizontal Scrollable Policy"),
|
|
|
|
|
P_("How the size of the content should be determined"),
|
|
|
|
|
GTK_TYPE_SCROLLABLE_POLICY,
|
|
|
|
|
GTK_SCROLL_MINIMUM,
|
2014-06-09 13:25:19 +00:00
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2010-10-26 00:59:02 +00:00
|
|
|
|
g_object_interface_install_property (iface, pspec);
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* GtkScrollable:vscroll-policy: (attributes org.gtk.Property.get=gtk_scrollable_get_vscroll_policy org.gtk.Property.set=gtk_scrollable_set_vscroll_policy)
|
2010-10-26 00:59:02 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Determines when vertical scrolling should start.
|
2010-10-26 00:59:02 +00:00
|
|
|
|
*/
|
|
|
|
|
pspec = g_param_spec_enum ("vscroll-policy",
|
|
|
|
|
P_("Vertical Scrollable Policy"),
|
|
|
|
|
P_("How the size of the content should be determined"),
|
|
|
|
|
GTK_TYPE_SCROLLABLE_POLICY,
|
|
|
|
|
GTK_SCROLL_MINIMUM,
|
2014-06-09 13:25:19 +00:00
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2010-10-26 00:59:02 +00:00
|
|
|
|
g_object_interface_install_property (iface, pspec);
|
2010-10-18 04:21:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* gtk_scrollable_get_hadjustment: (attributes org.gtk.Method.get_property=hadjustment)
|
|
|
|
|
* @scrollable: a `GtkScrollable`
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Retrieves the `GtkAdjustment` used for horizontal scrolling.
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2022-01-01 16:39:45 +00:00
|
|
|
|
* Returns: (transfer none) (nullable): horizontal `GtkAdjustment`.
|
2021-02-26 04:24:08 +00:00
|
|
|
|
*/
|
2010-10-18 04:21:39 +00:00
|
|
|
|
GtkAdjustment *
|
|
|
|
|
gtk_scrollable_get_hadjustment (GtkScrollable *scrollable)
|
|
|
|
|
{
|
|
|
|
|
GtkAdjustment *adj = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), NULL);
|
|
|
|
|
|
|
|
|
|
g_object_get (scrollable, "hadjustment", &adj, NULL);
|
|
|
|
|
|
|
|
|
|
/* Horrid hack; g_object_get() returns a new reference but
|
|
|
|
|
* that contradicts the memory management conventions
|
|
|
|
|
* for accessors.
|
|
|
|
|
*/
|
|
|
|
|
if (adj)
|
|
|
|
|
g_object_unref (adj);
|
|
|
|
|
|
|
|
|
|
return adj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* gtk_scrollable_set_hadjustment: (attributes org.gtk.Method.set_property=hadjustment)
|
|
|
|
|
* @scrollable: a `GtkScrollable`
|
2021-05-19 11:24:34 +00:00
|
|
|
|
* @hadjustment: (nullable): a `GtkAdjustment`
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Sets the horizontal adjustment of the `GtkScrollable`.
|
|
|
|
|
*/
|
2010-10-18 04:21:39 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_scrollable_set_hadjustment (GtkScrollable *scrollable,
|
|
|
|
|
GtkAdjustment *hadjustment)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
|
|
|
|
|
g_return_if_fail (hadjustment == NULL || GTK_IS_ADJUSTMENT (hadjustment));
|
|
|
|
|
|
|
|
|
|
g_object_set (scrollable, "hadjustment", hadjustment, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* gtk_scrollable_get_vadjustment: (attributes org.gtk.Method.get_property=vadjustment)
|
|
|
|
|
* @scrollable: a `GtkScrollable`
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Retrieves the `GtkAdjustment` used for vertical scrolling.
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2022-01-01 16:39:45 +00:00
|
|
|
|
* Returns: (transfer none) (nullable): vertical `GtkAdjustment`.
|
2021-02-26 04:24:08 +00:00
|
|
|
|
*/
|
2010-10-18 04:21:39 +00:00
|
|
|
|
GtkAdjustment *
|
|
|
|
|
gtk_scrollable_get_vadjustment (GtkScrollable *scrollable)
|
|
|
|
|
{
|
|
|
|
|
GtkAdjustment *adj = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), NULL);
|
|
|
|
|
|
|
|
|
|
g_object_get (scrollable, "vadjustment", &adj, NULL);
|
|
|
|
|
|
|
|
|
|
/* Horrid hack; g_object_get() returns a new reference but
|
|
|
|
|
* that contradicts the memory management conventions
|
|
|
|
|
* for accessors.
|
|
|
|
|
*/
|
|
|
|
|
if (adj)
|
|
|
|
|
g_object_unref (adj);
|
|
|
|
|
|
|
|
|
|
return adj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* gtk_scrollable_set_vadjustment: (attributes org.gtk.Method.set_property=vadjustment)
|
|
|
|
|
* @scrollable: a `GtkScrollable`
|
2021-05-19 11:24:34 +00:00
|
|
|
|
* @vadjustment: (nullable): a `GtkAdjustment`
|
2010-10-18 04:21:39 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Sets the vertical adjustment of the `GtkScrollable`.
|
|
|
|
|
*/
|
2010-10-18 04:21:39 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_scrollable_set_vadjustment (GtkScrollable *scrollable,
|
|
|
|
|
GtkAdjustment *vadjustment)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
|
|
|
|
|
g_return_if_fail (vadjustment == NULL || GTK_IS_ADJUSTMENT (vadjustment));
|
|
|
|
|
|
|
|
|
|
g_object_set (scrollable, "vadjustment", vadjustment, NULL);
|
|
|
|
|
}
|
2010-10-26 00:59:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* gtk_scrollable_get_hscroll_policy: (attributes org.gtk.Method.get_property=hscroll-policy)
|
|
|
|
|
* @scrollable: a `GtkScrollable`
|
2010-10-26 00:59:02 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Gets the horizontal `GtkScrollablePolicy`.
|
2010-10-26 00:59:02 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Returns: The horizontal `GtkScrollablePolicy`.
|
|
|
|
|
*/
|
2010-10-26 00:59:02 +00:00
|
|
|
|
GtkScrollablePolicy
|
|
|
|
|
gtk_scrollable_get_hscroll_policy (GtkScrollable *scrollable)
|
|
|
|
|
{
|
|
|
|
|
GtkScrollablePolicy policy;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), GTK_SCROLL_MINIMUM);
|
|
|
|
|
|
|
|
|
|
g_object_get (scrollable, "hscroll-policy", &policy, NULL);
|
|
|
|
|
|
|
|
|
|
return policy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* gtk_scrollable_set_hscroll_policy: (attributes org.gtk.Method.set_property=hscroll-policy)
|
|
|
|
|
* @scrollable: a `GtkScrollable`
|
|
|
|
|
* @policy: the horizontal `GtkScrollablePolicy`
|
2010-10-26 00:59:02 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Sets the `GtkScrollablePolicy`.
|
|
|
|
|
*
|
|
|
|
|
* The policy determines whether horizontal scrolling should start
|
|
|
|
|
* below the minimum width or below the natural width.
|
|
|
|
|
*/
|
2010-10-26 00:59:02 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_scrollable_set_hscroll_policy (GtkScrollable *scrollable,
|
|
|
|
|
GtkScrollablePolicy policy)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
|
|
|
|
|
|
|
|
|
|
g_object_set (scrollable, "hscroll-policy", policy, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* gtk_scrollable_get_vscroll_policy: (attributes org.gtk.Method.get_property=vscroll-policy)
|
|
|
|
|
* @scrollable: a `GtkScrollable`
|
2010-10-26 00:59:02 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Gets the vertical `GtkScrollablePolicy`.
|
2010-10-26 00:59:02 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Returns: The vertical `GtkScrollablePolicy`.
|
|
|
|
|
*/
|
2010-10-26 00:59:02 +00:00
|
|
|
|
GtkScrollablePolicy
|
|
|
|
|
gtk_scrollable_get_vscroll_policy (GtkScrollable *scrollable)
|
|
|
|
|
{
|
|
|
|
|
GtkScrollablePolicy policy;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), GTK_SCROLL_MINIMUM);
|
|
|
|
|
|
|
|
|
|
g_object_get (scrollable, "vscroll-policy", &policy, NULL);
|
|
|
|
|
|
|
|
|
|
return policy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* gtk_scrollable_set_vscroll_policy: (attributes org.gtk.Method.set_property=vscroll-policy)
|
|
|
|
|
* @scrollable: a `GtkScrollable`
|
|
|
|
|
* @policy: the vertical `GtkScrollablePolicy`
|
2010-10-26 00:59:02 +00:00
|
|
|
|
*
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* Sets the `GtkScrollablePolicy`.
|
|
|
|
|
*
|
|
|
|
|
* The policy determines whether vertical scrolling should start
|
|
|
|
|
* below the minimum height or below the natural height.
|
|
|
|
|
*/
|
2010-10-26 00:59:02 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_scrollable_set_vscroll_policy (GtkScrollable *scrollable,
|
|
|
|
|
GtkScrollablePolicy policy)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_SCROLLABLE (scrollable));
|
|
|
|
|
|
|
|
|
|
g_object_set (scrollable, "vscroll-policy", policy, NULL);
|
|
|
|
|
}
|
2014-12-10 11:45:21 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_scrollable_get_border:
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* @scrollable: a `GtkScrollable`
|
2016-04-03 13:31:05 +00:00
|
|
|
|
* @border: (out caller-allocates): return location for the results
|
2014-12-10 11:45:21 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns the size of a non-scrolling border around the
|
2021-02-26 04:24:08 +00:00
|
|
|
|
* outside of the scrollable.
|
|
|
|
|
*
|
|
|
|
|
* An example for this would be treeview headers. GTK can use
|
|
|
|
|
* this information to display overlaid graphics, like the
|
|
|
|
|
* overshoot indication, at the right position.
|
2014-12-10 11:45:21 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if @border has been set
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_scrollable_get_border (GtkScrollable *scrollable,
|
|
|
|
|
GtkBorder *border)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), FALSE);
|
|
|
|
|
g_return_val_if_fail (border != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
if (GTK_SCROLLABLE_GET_IFACE (scrollable)->get_border)
|
|
|
|
|
return GTK_SCROLLABLE_GET_IFACE (scrollable)->get_border (scrollable, border);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|