gtk2/gtk/gtkadjustment.c

854 lines
23 KiB
C
Raw Normal View History

/* GTK - The GIMP Toolkit
1997-11-24 22:37:52 +00:00
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
1997-11-24 22:37:52 +00:00
* 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.
1997-11-24 22:37:52 +00:00
*
* 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/>.
1997-11-24 22:37:52 +00:00
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
1997-11-24 22:37:52 +00:00
#include "gtkadjustment.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkintl.h"
1997-11-24 22:37:52 +00:00
/**
* SECTION:gtkadjustment
* @Short_description: A representation of an adjustable bounded value
* @Title: GtkAdjustment
*
* The #GtkAdjustment object represents a value which has an associated lower
* and upper bound, together with step and page increments, and a page size.
* It is used within several GTK+ widgets, including
* #GtkSpinButton, #GtkViewport, and #GtkRange (which is a base class for
* #GtkHScrollbar, #GtkVScrollbar, #GtkHScale, and #GtkVScale).
*
* The #GtkAdjustment object does not update the value itself. Instead
* it is left up to the owner of the #GtkAdjustment to control the value.
*
* The owner of the #GtkAdjustment typically calls the
* gtk_adjustment_value_changed() and gtk_adjustment_changed() functions
* after changing the value and its bounds. This results in the emission of the
* #GtkAdjustment::value_changed or #GtkAdjustment::changed signal respectively.
*/
2011-01-05 22:03:57 +00:00
struct _GtkAdjustmentPrivate {
gdouble lower;
gdouble upper;
gdouble value;
gdouble step_increment;
gdouble page_increment;
gdouble page_size;
};
enum
{
PROP_0,
PROP_VALUE,
PROP_LOWER,
PROP_UPPER,
PROP_STEP_INCREMENT,
PROP_PAGE_INCREMENT,
PROP_PAGE_SIZE
};
1997-11-24 22:37:52 +00:00
enum
{
1997-11-24 22:37:52 +00:00
CHANGED,
VALUE_CHANGED,
LAST_SIGNAL
};
static void gtk_adjustment_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_adjustment_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_adjustment_dispatch_properties_changed (GObject *object,
guint n_pspecs,
GParamSpec **pspecs);
1997-11-24 22:37:52 +00:00
made the <widget>_signals[] arrays of type guint rather than gint. made Mon Mar 9 15:48:10 1998 Tim Janik <timj@gimp.org> * Signal signedness and naming corrections, plus GtkType fixes: * gtk/gtkadjustment.c: * gtk/gtkbutton.c: * gtk/gtkcheckmenuitem.c: * gtk/gtkclist.c: * gtk/gtkcolorsel.c: * gtk/gtkcontainer.c: * gtk/gtkcurve.c: * gtk/gtkdata.c: * gtk/gtkeditable.c: * gtk/gtkentry.c: * gtk/gtkhandlebox.c: * gtk/gtkinputdialog.c: * gtk/gtkitem.c: * gtk/gtklist.c: * gtk/gtkmenuitem.c: * gtk/gtkmenushell.c: * gtk/gtknotebook.c: * gtk/gtkstatusbar.c: * gtk/gtktoolbar.c: * gtk/gtktree.c: * gtk/gtktreeitem.c: * gtk/gtkwidget.c: * gtk/gtktogglebutton.c: * gtk/gtkwindow.c: made the <widget>_signals[] arrays of type guint rather than gint. * gtk/gtkwidget.c (gtk_widget_get_ancestor): made widget_type a GtkType. * gtk/gtkcombo.h: handler ids need to be of type guint (entry_change_id, list_change_id). * gtk/gtkaccelerator.c: changed signal_num to signal_id and typed it guint. * gtk/gtkmain.c: made gtk_ndebug_keys a guint. * gtk/gtkmenu.h: * gtk/gtkmenu.c: (gtk_menu_popup): made button a guint. (gtk_menu_set_active): made index a guint. * gtk/gtkmenuitem.h: * gtk/gtkmenuitem.c: made accelerator_signal a guint. * gtk/gtkoptionmenu.h: * gtk/gtkoptionmenu.c: (gtk_option_menu_set_history): made index a guint. * gtk/gtksignal.h: * gtk/gtksignal.c: * gtk/gtkobject.h: * gtk/gtkobject.c: changed a bunch of prototypes to take guints rather than gints. also made some conversions from guint to GtkType, left over from when the fundamental-types system was introduced. * gtk/gtkobject.h: * gtk/gtkobject.c: made object_data_id_index and obj_count guints. made *signals and nsignals guints in GtkObjectClass.
1998-03-09 15:16:28 +00:00
static guint adjustment_signals[LAST_SIGNAL] = { 0 };
1997-11-24 22:37:52 +00:00
static guint64 adjustment_changed_stamp = 0; /* protected by global gdk lock */
G_DEFINE_TYPE (GtkAdjustment, gtk_adjustment, G_TYPE_INITIALLY_UNOWNED)
1997-11-24 22:37:52 +00:00
static void
gtk_adjustment_class_init (GtkAdjustmentClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
gobject_class->set_property = gtk_adjustment_set_property;
gobject_class->get_property = gtk_adjustment_get_property;
gobject_class->dispatch_properties_changed = gtk_adjustment_dispatch_properties_changed;
doh, this was broken beyond believe. Tue Dec 12 23:46:44 2000 Tim Janik <timj@gtk.org> * gtk/stock-icons/Makefile.am: doh, this was broken beyond believe. * gtk/gtkbox.c: change property types from (u)long to (u)int for ::position and ::padding. * gtk/gtkcontainer.c: make ::border_width an INT property. * gtk/gtkpacker.c: make ::position an INT property. * gtk/gtkscrolledwindow.c (gtk_scrolled_window_adjustment_changed): guard against NULL h/v scrollbars, since this is used at construction time. * gtk/gtkclist.[hc]: nuked gtk_clist_construct(), implemented internal gtk_clist_constructor(). * gtk/gtkctree.[hc]: nuked gtk_ctree_construct(), implemented gtk_ctree_constructor(). * gtk/gtkprogressbar.c (gtk_progress_bar_class_init): property ::pulse_step should use ARG_PULSE_STEP, not ARG_FRACTION. * docs/reference/Makefile.am: fun stuff, disabled docs generation again, gtk-scan.c needs to introspec paramspecs, not GtkAgs. * gtk/gtkwidget.[hc]: removed gtk_widget_setv(), gtk_widget_getv(), gtk_widget_newv() and gtk_widget_get(). (gtk_widget_new): use g_object_new_valist(). (gtk_widget_set): use g_object_set_valist(). * gtk/gtkobject.[hc]: removed gtk_object_arg_get_info(), gtk_object_getv(), gtk_object_query_args(), gtk_object_newv(), gtk_object_class_add_signals(), gtk_object_class_user_signal_new(), gtk_object_class_user_signal_newv(), gtk_object_arg_set(), gtk_object_arg_get(), gtk_object_args_collect(), gtk_object_default_construct(), gtk_object_constructed(), GTK_CONSTRUCTED and GTK_OBJECT_CONSTRUCTED(). removed nsignals, signals and n_args members from GtkObjectClass. (gtk_object_new): use g_object_new_valist(). (gtk_object_set): use g_object_set_valist(). (gtk_object_get): use g_object_get_valist(). * gtk/gtkcompat.h: define gtk_object_default_construct(). * gtk/gtktypeutils.c (gtk_type_new): create constructed objects via g_object_new(). * gtk/*.c: removed gtk_object_class_add_signals() from class_init() fucntions, cleaned up method assignments (make sure your structures are setup properly before calling out). removed all GTK_CONSTRUCTED hacks ;)
2000-12-13 01:34:41 +00:00
class->changed = NULL;
class->value_changed = NULL;
/**
* GtkAdjustment:value:
*
* The value of the adjustment.
*
* Since: 2.4
*/
g_object_class_install_property (gobject_class,
PROP_VALUE,
g_param_spec_double ("value",
P_("Value"),
P_("The value of the adjustment"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
GTK_PARAM_READWRITE));
/**
* GtkAdjustment:lower:
*
* The minimum value of the adjustment.
*
* Since: 2.4
*/
g_object_class_install_property (gobject_class,
PROP_LOWER,
g_param_spec_double ("lower",
P_("Minimum Value"),
P_("The minimum value of the adjustment"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
GTK_PARAM_READWRITE));
/**
* GtkAdjustment:upper:
*
* The maximum value of the adjustment.
* Note that values will be restricted by
* <literal>upper - page-size</literal> if the page-size
* property is nonzero.
*
* Since: 2.4
*/
g_object_class_install_property (gobject_class,
PROP_UPPER,
g_param_spec_double ("upper",
P_("Maximum Value"),
P_("The maximum value of the adjustment"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
GTK_PARAM_READWRITE));
/**
* GtkAdjustment:step-increment:
*
* The step increment of the adjustment.
*
* Since: 2.4
*/
g_object_class_install_property (gobject_class,
PROP_STEP_INCREMENT,
g_param_spec_double ("step-increment",
P_("Step Increment"),
P_("The step increment of the adjustment"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
GTK_PARAM_READWRITE));
/**
* GtkAdjustment:page-increment:
*
* The page increment of the adjustment.
*
* Since: 2.4
*/
g_object_class_install_property (gobject_class,
PROP_PAGE_INCREMENT,
g_param_spec_double ("page-increment",
P_("Page Increment"),
P_("The page increment of the adjustment"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
GTK_PARAM_READWRITE));
/**
* GtkAdjustment:page-size:
*
* The page size of the adjustment.
* Note that the page-size is irrelevant and should be set to zero
* if the adjustment is used for a simple scalar value, e.g. in a
* #GtkSpinButton.
*
* Since: 2.4
*/
g_object_class_install_property (gobject_class,
PROP_PAGE_SIZE,
g_param_spec_double ("page-size",
P_("Page Size"),
P_("The page size of the adjustment"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
GTK_PARAM_READWRITE));
/**
* GtkAdjustment::changed:
* @adjustment: the object which received the signal.
*
* Emitted when one or more of the #GtkAdjustment fields have been changed,
* other than the value field.
*/
1997-11-24 22:37:52 +00:00
adjustment_signals[CHANGED] =
g_signal_new (I_("changed"),
G_OBJECT_CLASS_TYPE (class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
G_STRUCT_OFFSET (GtkAdjustmentClass, changed),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GtkAdjustment::value-changed:
* @adjustment: the object which received the signal.
*
* Emitted when the #GtkAdjustment value field has been changed.
*/
1997-11-24 22:37:52 +00:00
adjustment_signals[VALUE_CHANGED] =
g_signal_new (I_("value-changed"),
G_OBJECT_CLASS_TYPE (class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
G_STRUCT_OFFSET (GtkAdjustmentClass, value_changed),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
2011-01-05 22:03:57 +00:00
g_type_class_add_private (class, sizeof (GtkAdjustmentPrivate));
1997-11-24 22:37:52 +00:00
}
static void
gtk_adjustment_init (GtkAdjustment *adjustment)
{
2011-01-05 22:03:57 +00:00
adjustment->priv = G_TYPE_INSTANCE_GET_PRIVATE (adjustment,
GTK_TYPE_ADJUSTMENT,
GtkAdjustmentPrivate);
1997-11-24 22:37:52 +00:00
}
static void
gtk_adjustment_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
2011-01-05 22:03:57 +00:00
GtkAdjustmentPrivate *priv = adjustment->priv;
switch (prop_id)
{
case PROP_VALUE:
2011-01-05 22:03:57 +00:00
g_value_set_double (value, priv->value);
break;
case PROP_LOWER:
2011-01-05 22:03:57 +00:00
g_value_set_double (value, priv->lower);
break;
case PROP_UPPER:
2011-01-05 22:03:57 +00:00
g_value_set_double (value, priv->upper);
break;
case PROP_STEP_INCREMENT:
2011-01-05 22:03:57 +00:00
g_value_set_double (value, priv->step_increment);
break;
case PROP_PAGE_INCREMENT:
2011-01-05 22:03:57 +00:00
g_value_set_double (value, priv->page_increment);
break;
case PROP_PAGE_SIZE:
2011-01-05 22:03:57 +00:00
g_value_set_double (value, priv->page_size);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_adjustment_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
gdouble double_value = g_value_get_double (value);
2011-01-05 22:03:57 +00:00
GtkAdjustmentPrivate *priv = adjustment->priv;
switch (prop_id)
{
case PROP_VALUE:
gtk_adjustment_set_value (adjustment, double_value);
break;
case PROP_LOWER:
2011-01-05 22:03:57 +00:00
priv->lower = double_value;
break;
case PROP_UPPER:
2011-01-05 22:03:57 +00:00
priv->upper = double_value;
break;
case PROP_STEP_INCREMENT:
2011-01-05 22:03:57 +00:00
priv->step_increment = double_value;
break;
case PROP_PAGE_INCREMENT:
2011-01-05 22:03:57 +00:00
priv->page_increment = double_value;
break;
case PROP_PAGE_SIZE:
2011-01-05 22:03:57 +00:00
priv->page_size = double_value;
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_adjustment_dispatch_properties_changed (GObject *object,
guint n_pspecs,
GParamSpec **pspecs)
{
gboolean changed = FALSE;
gint i;
G_OBJECT_CLASS (gtk_adjustment_parent_class)->dispatch_properties_changed (object, n_pspecs, pspecs);
for (i = 0; i < n_pspecs; i++)
switch (pspecs[i]->param_id)
{
case PROP_LOWER:
case PROP_UPPER:
case PROP_STEP_INCREMENT:
case PROP_PAGE_INCREMENT:
case PROP_PAGE_SIZE:
changed = TRUE;
break;
default:
break;
}
if (changed)
{
adjustment_changed_stamp++;
gtk_adjustment_changed (GTK_ADJUSTMENT (object));
}
}
/**
* gtk_adjustment_new:
* @value: the initial value.
* @lower: the minimum value.
* @upper: the maximum value.
* @step_increment: the step increment.
* @page_increment: the page increment.
* @page_size: the page size.
*
* Creates a new #GtkAdjustment.
*
* Returns: a new #GtkAdjustment.
*/
GtkAdjustment *
gtk_adjustment_new (gdouble value,
gdouble lower,
gdouble upper,
gdouble step_increment,
gdouble page_increment,
gdouble page_size)
1997-11-24 22:37:52 +00:00
{
return g_object_new (GTK_TYPE_ADJUSTMENT,
"lower", lower,
"upper", upper,
"step-increment", step_increment,
"page-increment", page_increment,
"page-size", page_size,
"value", value,
NULL);
1997-11-24 22:37:52 +00:00
}
/**
* gtk_adjustment_get_value:
* @adjustment: a #GtkAdjustment
*
* Gets the current value of the adjustment. See
* gtk_adjustment_set_value ().
*
* Return value: The current value of the adjustment.
**/
gdouble
gtk_adjustment_get_value (GtkAdjustment *adjustment)
{
g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
2011-01-05 22:03:57 +00:00
return adjustment->priv->value;
}
/**
* gtk_adjustment_set_value:
* @adjustment: a #GtkAdjustment.
* @value: the new value.
*
* Sets the #GtkAdjustment value. The value is clamped to lie between
* #GtkAdjustment.lower and #GtkAdjustment.upper.
*
* Note that for adjustments which are used in a #GtkScrollbar, the effective
* range of allowed values goes from #GtkAdjustment.lower to
* #GtkAdjustment.upper - #GtkAdjustment.page_size.
*/
void
gtk_adjustment_set_value (GtkAdjustment *adjustment,
gdouble value)
{
2011-01-05 22:03:57 +00:00
GtkAdjustmentPrivate *priv;
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2011-01-05 22:03:57 +00:00
priv = adjustment->priv;
/* don't use CLAMP() so we don't end up below lower if upper - page_size
* is smaller than lower
*/
2011-01-05 22:03:57 +00:00
value = MIN (value, priv->upper - priv->page_size);
value = MAX (value, priv->lower);
2011-01-05 22:03:57 +00:00
if (value != priv->value)
{
2011-01-05 22:03:57 +00:00
priv->value = value;
gtk_adjustment_value_changed (adjustment);
}
}
/**
* gtk_adjustment_get_lower:
* @adjustment: a #GtkAdjustment
*
* Retrieves the minimum value of the adjustment.
*
* Return value: The current minimum value of the adjustment.
*
* Since: 2.14
**/
gdouble
gtk_adjustment_get_lower (GtkAdjustment *adjustment)
{
g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
2011-01-05 22:03:57 +00:00
return adjustment->priv->lower;
}
/**
* gtk_adjustment_set_lower:
* @adjustment: a #GtkAdjustment
* @lower: the new minimum value
*
* Sets the minimum value of the adjustment.
*
* When setting multiple adjustment properties via their individual
* setters, multiple "changed" signals will be emitted. However, since
* the emission of the "changed" signal is tied to the emission of the
* "GObject::notify" signals of the changed properties, it's possible
* to compress the "changed" signals into one by calling
* g_object_freeze_notify() and g_object_thaw_notify() around the
* calls to the individual setters.
*
* Alternatively, using a single g_object_set() for all the properties
* to change, or using gtk_adjustment_configure() has the same effect
* of compressing "changed" emissions.
*
* Since: 2.14
**/
void
gtk_adjustment_set_lower (GtkAdjustment *adjustment,
gdouble lower)
{
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2011-01-05 22:03:57 +00:00
if (lower != adjustment->priv->lower)
g_object_set (adjustment, "lower", lower, NULL);
}
/**
* gtk_adjustment_get_upper:
* @adjustment: a #GtkAdjustment
*
* Retrieves the maximum value of the adjustment.
*
* Return value: The current maximum value of the adjustment.
*
* Since: 2.14
**/
gdouble
gtk_adjustment_get_upper (GtkAdjustment *adjustment)
{
g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
2011-01-05 22:03:57 +00:00
return adjustment->priv->upper;
}
/**
* gtk_adjustment_set_upper:
* @adjustment: a #GtkAdjustment
* @upper: the new maximum value
*
* Sets the maximum value of the adjustment.
*
* Note that values will be restricted by
* <literal>upper - page-size</literal> if the page-size
* property is nonzero.
*
* See gtk_adjustment_set_lower() about how to compress multiple
* emissions of the "changed" signal when setting multiple adjustment
* properties.
*
* Since: 2.14
**/
void
gtk_adjustment_set_upper (GtkAdjustment *adjustment,
gdouble upper)
{
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2011-01-05 22:03:57 +00:00
if (upper != adjustment->priv->upper)
g_object_set (adjustment, "upper", upper, NULL);
}
/**
* gtk_adjustment_get_step_increment:
* @adjustment: a #GtkAdjustment
*
* Retrieves the step increment of the adjustment.
*
* Return value: The current step increment of the adjustment.
*
* Since: 2.14
**/
gdouble
gtk_adjustment_get_step_increment (GtkAdjustment *adjustment)
{
g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
2011-01-05 22:03:57 +00:00
return adjustment->priv->step_increment;
}
/**
* gtk_adjustment_set_step_increment:
* @adjustment: a #GtkAdjustment
* @step_increment: the new step increment
*
* Sets the step increment of the adjustment.
*
* See gtk_adjustment_set_lower() about how to compress multiple
* emissions of the "changed" signal when setting multiple adjustment
* properties.
*
* Since: 2.14
**/
void
gtk_adjustment_set_step_increment (GtkAdjustment *adjustment,
gdouble step_increment)
{
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2011-01-05 22:03:57 +00:00
if (step_increment != adjustment->priv->step_increment)
g_object_set (adjustment, "step-increment", step_increment, NULL);
}
/**
* gtk_adjustment_get_page_increment:
* @adjustment: a #GtkAdjustment
*
* Retrieves the page increment of the adjustment.
*
* Return value: The current page increment of the adjustment.
*
* Since: 2.14
**/
gdouble
gtk_adjustment_get_page_increment (GtkAdjustment *adjustment)
{
g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
2011-01-05 22:03:57 +00:00
return adjustment->priv->page_increment;
}
/**
* gtk_adjustment_set_page_increment:
* @adjustment: a #GtkAdjustment
* @page_increment: the new page increment
*
* Sets the page increment of the adjustment.
*
* See gtk_adjustment_set_lower() about how to compress multiple
* emissions of the "changed" signal when setting multiple adjustment
* properties.
*
* Since: 2.14
**/
void
gtk_adjustment_set_page_increment (GtkAdjustment *adjustment,
gdouble page_increment)
{
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2011-01-05 22:03:57 +00:00
if (page_increment != adjustment->priv->page_increment)
g_object_set (adjustment, "page-increment", page_increment, NULL);
}
/**
* gtk_adjustment_get_page_size:
* @adjustment: a #GtkAdjustment
*
* Retrieves the page size of the adjustment.
*
* Return value: The current page size of the adjustment.
*
* Since: 2.14
**/
gdouble
gtk_adjustment_get_page_size (GtkAdjustment *adjustment)
{
g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
2011-01-05 22:03:57 +00:00
return adjustment->priv->page_size;
}
/**
* gtk_adjustment_set_page_size:
* @adjustment: a #GtkAdjustment
* @page_size: the new page size
*
* Sets the page size of the adjustment.
*
* See gtk_adjustment_set_lower() about how to compress multiple
* emissions of the "changed" signal when setting multiple adjustment
* properties.
*
* Since: 2.14
**/
void
gtk_adjustment_set_page_size (GtkAdjustment *adjustment,
gdouble page_size)
{
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2011-01-05 22:03:57 +00:00
if (page_size != adjustment->priv->page_size)
g_object_set (adjustment, "page-size", page_size, NULL);
}
/**
* gtk_adjustment_configure:
* @adjustment: a #GtkAdjustment
* @value: the new value
* @lower: the new minimum value
* @upper: the new maximum value
* @step_increment: the new step increment
* @page_increment: the new page increment
* @page_size: the new page size
*
* Sets all properties of the adjustment at once.
*
* Use this function to avoid multiple emissions of the "changed"
* signal. See gtk_adjustment_set_lower() for an alternative way
* of compressing multiple emissions of "changed" into one.
*
* Since: 2.14
**/
void
gtk_adjustment_configure (GtkAdjustment *adjustment,
gdouble value,
gdouble lower,
gdouble upper,
gdouble step_increment,
gdouble page_increment,
gdouble page_size)
{
2011-01-05 22:03:57 +00:00
GtkAdjustmentPrivate *priv;
gboolean value_changed = FALSE;
guint64 old_stamp = adjustment_changed_stamp;
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2011-01-05 22:03:57 +00:00
priv = adjustment->priv;
g_object_freeze_notify (G_OBJECT (adjustment));
g_object_set (adjustment,
"lower", lower,
"upper", upper,
"step-increment", step_increment,
"page-increment", page_increment,
"page-size", page_size,
NULL);
/* don't use CLAMP() so we don't end up below lower if upper - page_size
* is smaller than lower
*/
value = MIN (value, upper - page_size);
value = MAX (value, lower);
2011-01-05 22:03:57 +00:00
if (value != priv->value)
{
/* set value manually to make sure "changed" is emitted with the
* new value in place and is emitted before "value-changed"
*/
2011-01-05 22:03:57 +00:00
priv->value = value;
value_changed = TRUE;
}
g_object_thaw_notify (G_OBJECT (adjustment));
if (old_stamp == adjustment_changed_stamp)
gtk_adjustment_changed (adjustment); /* force emission before ::value-changed */
if (value_changed)
gtk_adjustment_value_changed (adjustment);
}
/**
* gtk_adjustment_changed:
* @adjustment: a #GtkAdjustment
*
* Emits a #GtkAdjustment::changed signal from the #GtkAdjustment.
* This is typically called by the owner of the #GtkAdjustment after it has
* changed any of the #GtkAdjustment fields other than the value.
*/
void
gtk_adjustment_changed (GtkAdjustment *adjustment)
{
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
g_signal_emit (adjustment, adjustment_signals[CHANGED], 0);
}
/**
* gtk_adjustment_value_changed:
* @adjustment: a #GtkAdjustment
*
* Emits a #GtkAdjustment::value_changed signal from the #GtkAdjustment.
* This is typically called by the owner of the #GtkAdjustment after it has
* changed the #GtkAdjustment value field.
*/
void
gtk_adjustment_value_changed (GtkAdjustment *adjustment)
{
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
g_signal_emit (adjustment, adjustment_signals[VALUE_CHANGED], 0);
g_object_notify (G_OBJECT (adjustment), "value");
}
/**
* gtk_adjustment_clamp_page:
* @adjustment: a #GtkAdjustment.
* @lower: the lower value.
* @upper: the upper value.
*
* Updates the #GtkAdjustment #GtkAdjustment.value to ensure that the range
* between @lower and @upper is in the current page (i.e. between
* #GtkAdjustment.value and #GtkAdjustment.value + #GtkAdjustment.page_size).
* If the range is larger than the page size, then only the start of it will
* be in the current page.
* A #GtkAdjustment::changed signal will be emitted if the value is changed.
*/
void
gtk_adjustment_clamp_page (GtkAdjustment *adjustment,
gdouble lower,
gdouble upper)
{
2011-01-05 22:03:57 +00:00
GtkAdjustmentPrivate *priv;
gboolean need_emission;
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2011-01-05 22:03:57 +00:00
priv = adjustment->priv;
lower = CLAMP (lower, priv->lower, priv->upper);
upper = CLAMP (upper, priv->lower, priv->upper);
need_emission = FALSE;
2011-01-05 22:03:57 +00:00
if (priv->value + priv->page_size < upper)
{
2011-01-05 22:03:57 +00:00
priv->value = upper - priv->page_size;
need_emission = TRUE;
}
2011-01-05 22:03:57 +00:00
if (priv->value > lower)
{
2011-01-05 22:03:57 +00:00
priv->value = lower;
need_emission = TRUE;
}
if (need_emission)
gtk_adjustment_value_changed (adjustment);
}
/**
* gtk_adjustment_get_minimum_increment:
* @adjustment: a #GtkAdjustment
*
* Gets the smaller of step increment and page increment.
*
* Returns: the minimum increment of @adjustment
*
* Since: 3.2
*/
gdouble
gtk_adjustment_get_minimum_increment (GtkAdjustment *adjustment)
{
GtkAdjustmentPrivate *priv;
gdouble minimum_increment;
g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0);
priv = adjustment->priv;
if (priv->step_increment != 0 && priv->page_increment != 0)
{
if (ABS (priv->step_increment) < ABS (priv->page_increment))
minimum_increment = priv->step_increment;
else
minimum_increment = priv->page_increment;
}
else if (priv->step_increment == 0 && priv->page_increment == 0)
{
minimum_increment = 0;
}
else if (priv->step_increment == 0)
{
minimum_increment = priv->page_increment;
}
else
{
minimum_increment = priv->step_increment;
}
return minimum_increment;
}