Add an icons property, make gtk_scale_button_new() a convenience function.

2007-06-09  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtkscalebutton.c: Add an icons property, make
        gtk_scale_button_new() a convenience function.  (#445855,
        Murray Cumming)



svn path=/trunk/; revision=18088
This commit is contained in:
Matthias Clasen
2007-06-10 01:26:28 +00:00
committed by Matthias Clasen
parent 08d065b500
commit 0d7f4951d1
2 changed files with 71 additions and 37 deletions

View File

@ -1,3 +1,9 @@
2007-06-09 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkscalebutton.c: Add an icons property, make
gtk_scale_button_new() a convenience function. (#445855,
Murray Cumming)
2007-06-09 Matthias Clasen <mclasen@redhat.com> 2007-06-09 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkhscale.c (gtk_hscale_new): * gtk/gtkhscale.c (gtk_hscale_new):

View File

@ -51,6 +51,7 @@
#include "gtkwindow.h" #include "gtkwindow.h"
#include "gtkmarshalers.h" #include "gtkmarshalers.h"
#include "gtkstock.h" #include "gtkstock.h"
#include "gtkprivate.h"
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
@ -72,7 +73,8 @@ enum {
PROP_0, PROP_0,
PROP_VALUE, PROP_VALUE,
PROP_SIZE, PROP_SIZE,
PROP_ADJUSTMENT PROP_ADJUSTMENT,
PROP_ICONS
}; };
struct _GtkScaleButtonPrivate { struct _GtkScaleButtonPrivate {
@ -167,7 +169,7 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass)
-G_MAXDOUBLE, -G_MAXDOUBLE,
G_MAXDOUBLE, G_MAXDOUBLE,
0, 0,
G_PARAM_READWRITE)); GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_SIZE, PROP_SIZE,
@ -176,7 +178,7 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass)
P_("The icon size"), P_("The icon size"),
GTK_TYPE_ICON_SIZE, GTK_TYPE_ICON_SIZE,
GTK_ICON_SIZE_SMALL_TOOLBAR, GTK_ICON_SIZE_SMALL_TOOLBAR,
G_PARAM_READWRITE)); GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_ADJUSTMENT, PROP_ADJUSTMENT,
@ -184,8 +186,36 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass)
P_("Adjustment"), P_("Adjustment"),
P_("The GtkAdjustment that contains the current value of this scale button object"), P_("The GtkAdjustment that contains the current value of this scale button object"),
GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT,
G_PARAM_READWRITE)); GTK_PARAM_READWRITE));
/**
* GtkScaleButton:icons:
*
* The names of the icons to be used by the scale button.
* The first item in the array will be used in the button
* when the current value is the lowest value, the second
* item for the highest value. All the subsequent icons will
* be used for all the other values, spread evenly over the
* range of values.
*
* If there's only one icon name in the @icons array, it will
* be used for all the values. If only two icon names are in
* the @icons array, the first one will be used for the bottom
* 50% of the scale, and the second one for the top 50%.
*
* It is recommended to use at least 3 icons so that the
* #GtkScaleButton reflects the current value of the scale
* better for the users.
*
* Since: 2.12
*/
g_object_class_install_property (gobject_class,
PROP_ICONS,
g_param_spec_boxed ("icons",
P_("Icons"),
P_("List of icon names"),
G_TYPE_STRV,
GTK_PARAM_READWRITE));
/** /**
* GtkScaleButton::value-changed: * GtkScaleButton::value-changed:
* @button: the object that received the signal * @button: the object that received the signal
@ -336,6 +366,10 @@ gtk_scale_button_set_property (GObject *object,
case PROP_ADJUSTMENT: case PROP_ADJUSTMENT:
gtk_scale_button_set_adjustment (button, g_value_get_object (value)); gtk_scale_button_set_adjustment (button, g_value_get_object (value));
break; break;
case PROP_ICONS:
gtk_scale_button_set_icons (button,
(const gchar **)g_value_get_boxed (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -365,6 +399,9 @@ gtk_scale_button_get_property (GObject *object,
case PROP_ADJUSTMENT: case PROP_ADJUSTMENT:
g_value_set_object (value, gtk_scale_button_get_adjustment (button)); g_value_set_object (value, gtk_scale_button_get_adjustment (button));
break; break;
case PROP_ICONS:
g_value_set_boxed (value, priv->icon_list);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -430,22 +467,15 @@ gtk_scale_button_new (GtkIconSize size,
const gchar **icons) const gchar **icons)
{ {
GtkScaleButton *button; GtkScaleButton *button;
GtkScaleButtonPrivate *priv; GtkObject *adj;
button = g_object_new (GTK_TYPE_SCALE_BUTTON, NULL); adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
priv = button->priv;
button = g_object_new (GTK_TYPE_SCALE_BUTTON,
if (icons != NULL) "adjustment", adj,
gtk_scale_button_set_icons (button, icons); "icons", icons,
"size", size,
gtk_range_set_range (GTK_RANGE (priv->scale), min, max); NULL);
gtk_range_set_increments (GTK_RANGE (priv->scale), step, 10 * step);
if (priv->size != size)
{
priv->size = size;
gtk_scale_button_update_icon (button);
}
return GTK_WIDGET (button); return GTK_WIDGET (button);
} }
@ -477,9 +507,10 @@ gtk_scale_button_get_value (GtkScaleButton * button)
* @button: a #GtkScaleButton * @button: a #GtkScaleButton
* @value: new value of the scale button * @value: new value of the scale button
* *
* Sets the current value of the scale; if the value is outside the minimum or * Sets the current value of the scale; if the value is outside
* maximum range values, it will be clamped to fit inside them. The scale button * the minimum or maximum range values, it will be clamped to fit
* emits the "value_changed" signal if the value changes. * inside them. The scale button emits the #GtkScaleButton::value-changed
* signal if the value changes.
* *
* Since: 2.12 * Since: 2.12
*/ */
@ -501,16 +532,8 @@ gtk_scale_button_set_value (GtkScaleButton *button,
* @button: a #GtkScaleButton * @button: a #GtkScaleButton
* @icons: a %NULL-terminated array of icon names * @icons: a %NULL-terminated array of icon names
* *
* Sets the icons to be used by the scale button. The first item in the array * Sets the icons to be used by the scale button.
* will be used in the button when the current value is the lowest value, the * For details, see the #GtkScaleButton:icons property.
* second item for the highest value. All the subsequent icons will be used for
* all the other values, spread evenly over the range of values.
*
* If there's only one icon in the @icons array, it will be used for all the
* values. If only two icons are in the @icons array, the first one will be
* used for the bottom 50% of the scale, and the second one for the top 50%.
* So it is recommended to use at least 3 icons so that the #GtkScaleButton
* reflects the current value of the scale better for the users.
* *
* Since 2.12 * Since 2.12
*/ */
@ -519,20 +542,22 @@ gtk_scale_button_set_icons (GtkScaleButton *button,
const gchar **icons) const gchar **icons)
{ {
GtkScaleButtonPrivate *priv; GtkScaleButtonPrivate *priv;
gchar **tmp;
g_return_if_fail (GTK_IS_SCALE_BUTTON (button)); g_return_if_fail (GTK_IS_SCALE_BUTTON (button));
g_return_if_fail (icons != NULL);
g_return_if_fail (icons[0] != NULL);
priv = button->priv; priv = button->priv;
g_strfreev (priv->icon_list); tmp = priv->icon_list;
priv->icon_list = g_strdupv ((gchar **) icons); priv->icon_list = g_strdupv ((gchar **) icons);
g_strfreev (tmp);
gtk_scale_button_update_icon (button); gtk_scale_button_update_icon (button);
g_object_notify (G_OBJECT (button), "icons");
} }
/** /**
* gtk_scale_button_get_adjustment * gtk_scale_button_get_adjustment:
* @button: a #GtkScaleButton * @button: a #GtkScaleButton
* *
* Gets the #GtkAdjustment associated with the #GtkScaleButton's scale. * Gets the #GtkAdjustment associated with the #GtkScaleButton's scale.
@ -560,7 +585,8 @@ gtk_scale_button_get_adjustment (GtkScaleButton *button)
* @button: a #GtkScaleButton * @button: a #GtkScaleButton
* @adjustment: a #GtkAdjustment * @adjustment: a #GtkAdjustment
* *
* Sets the #GtkAdjustment to be used as a model for the #GtkScaleButton's scale. * Sets the #GtkAdjustment to be used as a model
* for the #GtkScaleButton's scale.
* See gtk_range_set_adjustment() for details. * See gtk_range_set_adjustment() for details.
* *
* Since: 2.12 * Since: 2.12
@ -574,6 +600,8 @@ gtk_scale_button_set_adjustment (GtkScaleButton *button,
gtk_range_set_adjustment (GTK_RANGE (button->priv->scale), gtk_range_set_adjustment (GTK_RANGE (button->priv->scale),
adjustment); adjustment);
g_object_notify (G_OBJECT (button), "adjustment");
} }
/* /*