X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkscalebutton.c;h=f10bb0308d7787a2ad7e65667520ca9f2e177ff4;hb=6f1476edd3fbe31259e59ca3f03a01bf0f8ff67b;hp=b6933bc23cec0ff5667b537211bbc8337317a4cc;hpb=ba5fbdb32b4d10066b967bedcf709c1337d648e8;p=~andy%2Fgtk diff --git a/gtk/gtkscalebutton.c b/gtk/gtkscalebutton.c index b6933bc23..f10bb0308 100644 --- a/gtk/gtkscalebutton.c +++ b/gtk/gtkscalebutton.c @@ -21,9 +21,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library. If not, see . */ /* @@ -35,6 +33,8 @@ #include "config.h" +#include "gtkscalebutton.h" + #ifndef _WIN32 #define _GNU_SOURCE #endif @@ -42,24 +42,32 @@ #include #include -#include -#include - -#include "gtkmain.h" -#include "gtkintl.h" +#include "gtkadjustment.h" #include "gtkbindings.h" -#include "gtkhscale.h" -#include "gtkvscale.h" #include "gtkframe.h" -#include "gtkhbox.h" -#include "gtkvbox.h" -#include "gtkwindow.h" +#include "gtkmain.h" #include "gtkmarshalers.h" -#include "gtkstock.h" +#include "gtkorientable.h" #include "gtkprivate.h" -#include "gtkscalebutton.h" +#include "gtkscale.h" +#include "gtkstock.h" +#include "gtkbox.h" +#include "gtkwindow.h" +#include "gtktypebuiltins.h" +#include "gtkintl.h" +#include "a11y/gtkscalebuttonaccessible.h" + +/** + * SECTION:gtkscalebutton + * @Short_description: A button which pops up a scale + * @Title: GtkScaleButton + * + * #GtkScaleButton provides a button which pops up a scale widget. + * This kind of widget is commonly used for volume controls in multimedia + * applications, and GTK+ provides a #GtkVolumeButton subclass that + * is tailored for this use case. + */ -#include "gtkalias.h" #define SCALE_SIZE 100 #define CLICK_TIMEOUT 250 @@ -84,11 +92,12 @@ enum PROP_ICONS }; -#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SCALE_BUTTON, GtkScaleButtonPrivate)) - struct _GtkScaleButtonPrivate { + GtkWidget *plus_button; + GtkWidget *minus_button; GtkWidget *dock; + GtkWidget *box; GtkWidget *scale; GtkWidget *image; @@ -103,6 +112,9 @@ struct _GtkScaleButtonPrivate gchar **icon_list; + GdkDevice *grab_pointer; + GdkDevice *grab_keyboard; + GtkAdjustment *adjustment; /* needed because it must be settable in init() */ }; @@ -119,6 +131,8 @@ static void gtk_scale_button_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void gtk_scale_button_set_orientation_private (GtkScaleButton *button, + GtkOrientation orientation); static gboolean gtk_scale_button_scroll (GtkWidget *widget, GdkEventScroll *event); static void gtk_scale_button_screen_changed (GtkWidget *widget, @@ -154,11 +168,13 @@ static void gtk_scale_button_update_icon (GtkScaleButton *button); static void gtk_scale_button_scale_value_changed(GtkRange *range); /* see below for scale definitions */ -static GtkWidget *gtk_scale_button_scale_box_new(GtkScaleButton *button); +static GtkWidget *gtk_scale_button_scale_new (GtkScaleButton *button); -static guint signals[LAST_SIGNAL] = { 0, }; +G_DEFINE_TYPE_WITH_CODE (GtkScaleButton, gtk_scale_button, GTK_TYPE_BUTTON, + G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, + NULL)) -G_DEFINE_TYPE (GtkScaleButton, gtk_scale_button, GTK_TYPE_BUTTON) +static guint signals[LAST_SIGNAL] = { 0, }; static void gtk_scale_button_class_init (GtkScaleButtonClass *klass) @@ -185,16 +201,16 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass) * * The orientation of the #GtkScaleButton's popup window. * + * Note that since GTK+ 2.16, #GtkScaleButton implements the + * #GtkOrientable interface which has its own @orientation + * property. However we redefine the property here in order to + * override its default horizontal orientation. + * * Since: 2.14 **/ - g_object_class_install_property (gobject_class, - PROP_ORIENTATION, - g_param_spec_enum ("orientation", - P_("Orientation"), - P_("The orientation of the scale"), - GTK_TYPE_ORIENTATION, - GTK_ORIENTATION_VERTICAL, - GTK_PARAM_READWRITE)); + g_object_class_override_property (gobject_class, + PROP_ORIENTATION, + "orientation"); g_object_class_install_property (gobject_class, PROP_VALUE, @@ -316,26 +332,31 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass) /* Key bindings */ binding_set = gtk_binding_set_by_class (widget_class); - gtk_binding_entry_add_signal (binding_set, GDK_space, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0, "popup", 0); - gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0, "popup", 0); - gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0, "popup", 0); - gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0, "popup", 0); - gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0, "popup", 0); - gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "popdown", 0); + + gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCALE_BUTTON_ACCESSIBLE); } static void gtk_scale_button_init (GtkScaleButton *button) { GtkScaleButtonPrivate *priv; + GtkWidget *frame; - button->priv = priv = GET_PRIVATE (button); + button->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (button, + GTK_TYPE_SCALE_BUTTON, + GtkScaleButtonPrivate); priv->timeout = FALSE; priv->click_id = 0; @@ -363,24 +384,41 @@ gtk_scale_button_init (GtkScaleButton *button) G_CALLBACK (cb_dock_grab_broken_event), button); gtk_window_set_decorated (GTK_WINDOW (priv->dock), FALSE); + /* frame */ + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); + gtk_container_add (GTK_CONTAINER (priv->dock), frame); + + /* box for scale and +/- buttons */ + priv->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + gtk_container_add (GTK_CONTAINER (frame), priv->box); + /* + */ - button->plus_button = gtk_button_new_with_label ("+"); - gtk_button_set_relief (GTK_BUTTON (button->plus_button), GTK_RELIEF_NONE); - g_signal_connect (button->plus_button, "button-press-event", + priv->plus_button = gtk_button_new_with_label ("+"); + gtk_button_set_relief (GTK_BUTTON (priv->plus_button), GTK_RELIEF_NONE); + g_signal_connect (priv->plus_button, "button-press-event", G_CALLBACK (cb_button_press), button); - g_signal_connect (button->plus_button, "button-release-event", + g_signal_connect (priv->plus_button, "button-release-event", G_CALLBACK (cb_button_release), button); + gtk_box_pack_start (GTK_BOX (priv->box), priv->plus_button, FALSE, FALSE, 0); /* - */ - button->minus_button = gtk_button_new_with_label ("-"); - gtk_button_set_relief (GTK_BUTTON (button->minus_button), GTK_RELIEF_NONE); - g_signal_connect (button->minus_button, "button-press-event", + priv->minus_button = gtk_button_new_with_label ("-"); + gtk_button_set_relief (GTK_BUTTON (priv->minus_button), GTK_RELIEF_NONE); + g_signal_connect (priv->minus_button, "button-press-event", G_CALLBACK (cb_button_press), button); - g_signal_connect (button->minus_button, "button-release-event", + g_signal_connect (priv->minus_button, "button-release-event", G_CALLBACK (cb_button_release), button); + gtk_box_pack_end (GTK_BOX (priv->box), priv->minus_button, FALSE, FALSE, 0); - priv->adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 100.0, 2, 20, 0)); + priv->adjustment = gtk_adjustment_new (0.0, 0.0, 100.0, 2, 20, 0); g_object_ref_sink (priv->adjustment); + + /* the scale */ + priv->scale = gtk_scale_button_scale_new (button); + gtk_container_add (GTK_CONTAINER (priv->box), priv->scale); + + gtk_widget_add_events (GTK_WIDGET (button), GDK_SCROLL_MASK); } static GObject * @@ -390,7 +428,6 @@ gtk_scale_button_constructor (GType type, { GObject *object; GtkScaleButton *button; - GtkWidget *frame, *box; GtkScaleButtonPrivate *priv; object = G_OBJECT_CLASS (gtk_scale_button_parent_class)->constructor (type, n_construct_properties, construct_params); @@ -399,15 +436,6 @@ gtk_scale_button_constructor (GType type, priv = button->priv; - /* frame */ - frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); - gtk_container_add (GTK_CONTAINER (priv->dock), frame); - - /* box with scale and +/- buttons */ - box = gtk_scale_button_scale_box_new (button); - gtk_container_add (GTK_CONTAINER (frame), box); - /* set button text and size */ priv->size = GTK_ICON_SIZE_SMALL_TOOLBAR; gtk_scale_button_update_icon (button); @@ -426,7 +454,7 @@ gtk_scale_button_set_property (GObject *object, switch (prop_id) { case PROP_ORIENTATION: - gtk_scale_button_set_orientation (button, g_value_get_enum (value)); + gtk_scale_button_set_orientation_private (button, g_value_get_enum (value)); break; case PROP_VALUE: gtk_scale_button_set_value (button, g_value_get_double (value)); @@ -531,13 +559,14 @@ gtk_scale_button_dispose (GObject *object) /** * gtk_scale_button_new: - * @size: a stock icon size + * @size: (type int): a stock icon size * @min: the minimum value of the scale (usually 0) * @max: the maximum value of the scale (usually 100) * @step: the stepping of value when a scroll-wheel event, * or up/down arrow event occurs (usually 2) - * @icons: a %NULL-terminated array of icon names, or %NULL if - * you want to set the list later with gtk_scale_button_set_icons() + * @icons: (allow-none) (array zero-terminated=1): a %NULL-terminated + * array of icon names, or %NULL if you want to set the list + * later with gtk_scale_button_set_icons() * * Creates a #GtkScaleButton, with a range between @min and @max, with * a stepping of @step. @@ -554,12 +583,12 @@ gtk_scale_button_new (GtkIconSize size, const gchar **icons) { GtkScaleButton *button; - GtkObject *adj; + GtkAdjustment *adjustment; - adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0); + adjustment = gtk_adjustment_new (min, min, max, step, 10 * step, 0); button = g_object_new (GTK_TYPE_SCALE_BUTTON, - "adjustment", adj, + "adjustment", adjustment, "icons", icons, "size", size, NULL); @@ -617,7 +646,7 @@ gtk_scale_button_set_value (GtkScaleButton *button, /** * gtk_scale_button_set_icons: * @button: a #GtkScaleButton - * @icons: a %NULL-terminated array of icon names + * @icons: (array zero-terminated=1): a %NULL-terminated array of icon names * * Sets the icons to be used by the scale button. * For details, see the #GtkScaleButton:icons property. @@ -650,7 +679,7 @@ gtk_scale_button_set_icons (GtkScaleButton *button, * Gets the #GtkAdjustment associated with the #GtkScaleButton's scale. * See gtk_range_get_adjustment() for details. * - * Returns: the adjustment associated with the scale + * Returns: (transfer none): the adjustment associated with the scale * * Since: 2.12 */ @@ -678,8 +707,9 @@ gtk_scale_button_set_adjustment (GtkScaleButton *button, GtkAdjustment *adjustment) { g_return_if_fail (GTK_IS_SCALE_BUTTON (button)); + if (!adjustment) - adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); else g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); @@ -696,83 +726,13 @@ gtk_scale_button_set_adjustment (GtkScaleButton *button, } } -/** - * gtk_scale_button_get_orientation: - * @button: a #GtkScaleButton - * - * Gets the orientation of the #GtkScaleButton's popup window. - * - * Returns: the #GtkScaleButton's orientation. - * - * Since: 2.14 - **/ -GtkOrientation -gtk_scale_button_get_orientation (GtkScaleButton *button) -{ - g_return_val_if_fail (GTK_IS_SCALE_BUTTON (button), GTK_ORIENTATION_VERTICAL); - - return button->priv->orientation; -} - -/** - * gtk_scale_button_set_orientation: - * @button: a #GtkScaleButton - * @orientation: the new orientation - * - * Sets the orientation of the #GtkScaleButton's popup window. - * - * Since: 2.14 - **/ -void -gtk_scale_button_set_orientation (GtkScaleButton *button, - GtkOrientation orientation) -{ - GtkScaleButtonPrivate *priv; - - g_return_if_fail (GTK_IS_SCALE_BUTTON (button)); - - priv = button->priv; - - if (orientation != priv->orientation) - { - priv->orientation = orientation; - - if (priv->scale) - { - GtkWidget *box = priv->scale->parent; - GtkWidget *frame = box->parent; - - g_object_ref (button->plus_button); - g_object_ref (button->minus_button); - - gtk_container_remove (GTK_CONTAINER (box), button->plus_button); - gtk_container_remove (GTK_CONTAINER (box), button->minus_button); - gtk_container_remove (GTK_CONTAINER (box), priv->scale); - gtk_container_remove (GTK_CONTAINER (frame), box); - - box = gtk_scale_button_scale_box_new (button); - gtk_container_add (GTK_CONTAINER (frame), box); - - /* FIXME: without this, the popup window appears as a square - * after changing the orientation - */ - gtk_window_resize (GTK_WINDOW (priv->dock), 1, 1); - - g_object_unref (button->plus_button); - g_object_unref (button->minus_button); - } - - g_object_notify (G_OBJECT (button), "orientation"); - } -} - /** * gtk_scale_button_get_plus_button: * @button: a #GtkScaleButton * * Retrieves the plus button of the #GtkScaleButton. * - * Returns: the plus button of the #GtkScaleButton. + * Returns: (transfer none): the plus button of the #GtkScaleButton * * Since: 2.14 */ @@ -781,7 +741,7 @@ gtk_scale_button_get_plus_button (GtkScaleButton *button) { g_return_val_if_fail (GTK_IS_SCALE_BUTTON (button), NULL); - return button->plus_button; + return button->priv->plus_button; } /** @@ -790,7 +750,7 @@ gtk_scale_button_get_plus_button (GtkScaleButton *button) * * Retrieves the minus button of the #GtkScaleButton. * - * Returns: the minus button of the #GtkScaleButton. + * Returns: (transfer none): the minus button of the #GtkScaleButton * * Since: 2.14 */ @@ -799,7 +759,7 @@ gtk_scale_button_get_minus_button (GtkScaleButton *button) { g_return_val_if_fail (GTK_IS_SCALE_BUTTON (button), NULL); - return button->minus_button; + return button->priv->minus_button; } /** @@ -808,7 +768,7 @@ gtk_scale_button_get_minus_button (GtkScaleButton *button) * * Retrieves the popup of the #GtkScaleButton. * - * Returns: the popup of the #GtkScaleButton + * Returns: (transfer none): the popup of the #GtkScaleButton * * Since: 2.14 */ @@ -820,6 +780,56 @@ gtk_scale_button_get_popup (GtkScaleButton *button) return button->priv->dock; } +static void +gtk_scale_button_set_orientation_private (GtkScaleButton *button, + GtkOrientation orientation) +{ + GtkScaleButtonPrivate *priv = button->priv; + + if (orientation != priv->orientation) + { + priv->orientation = orientation; + + gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), + orientation); + gtk_container_child_set (GTK_CONTAINER (priv->box), + priv->plus_button, + "pack-type", + orientation == GTK_ORIENTATION_VERTICAL ? + GTK_PACK_START : GTK_PACK_END, + NULL); + gtk_container_child_set (GTK_CONTAINER (priv->box), + priv->minus_button, + "pack-type", + orientation == GTK_ORIENTATION_VERTICAL ? + GTK_PACK_END : GTK_PACK_START, + NULL); + + gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->scale), + orientation); + + if (orientation == GTK_ORIENTATION_VERTICAL) + { + gtk_widget_set_size_request (GTK_WIDGET (priv->scale), + -1, SCALE_SIZE); + gtk_range_set_inverted (GTK_RANGE (priv->scale), TRUE); + } + else + { + gtk_widget_set_size_request (GTK_WIDGET (priv->scale), + SCALE_SIZE, -1); + gtk_range_set_inverted (GTK_RANGE (priv->scale), FALSE); + } + + /* FIXME: without this, the popup window appears as a square + * after changing the orientation + */ + gtk_window_resize (GTK_WINDOW (priv->dock), 1, 1); + + g_object_notify (G_OBJECT (button), "orientation"); + } +} + /* * button callbacks. */ @@ -830,12 +840,12 @@ gtk_scale_button_scroll (GtkWidget *widget, { GtkScaleButton *button; GtkScaleButtonPrivate *priv; - GtkAdjustment *adj; + GtkAdjustment *adjustment; gdouble d; button = GTK_SCALE_BUTTON (widget); priv = button->priv; - adj = priv->adjustment; + adjustment = priv->adjustment; if (event->type != GDK_SCROLL) return FALSE; @@ -843,15 +853,15 @@ gtk_scale_button_scroll (GtkWidget *widget, d = gtk_scale_button_get_value (button); if (event->direction == GDK_SCROLL_UP) { - d += adj->step_increment; - if (d > adj->upper) - d = adj->upper; + d += gtk_adjustment_get_step_increment (adjustment); + if (d > gtk_adjustment_get_upper (adjustment)) + d = gtk_adjustment_get_upper (adjustment); } else { - d -= adj->step_increment; - if (d < adj->lower) - d = adj->lower; + d -= gtk_adjustment_get_step_increment (adjustment); + if (d < gtk_adjustment_get_lower (adjustment)) + d = gtk_adjustment_get_lower (adjustment); } gtk_scale_button_set_value (button, d); @@ -865,7 +875,7 @@ gtk_scale_button_screen_changed (GtkWidget *widget, GtkScaleButton *button = (GtkScaleButton *) widget; GtkScaleButtonPrivate *priv; GdkScreen *screen; - GValue value = { 0, }; + GValue value = G_VALUE_INIT; if (gtk_widget_has_screen (widget) == FALSE) return; @@ -890,27 +900,32 @@ gtk_scale_popup (GtkWidget *widget, GdkEvent *event, guint32 time) { + GtkAllocation allocation, dock_allocation, scale_allocation; GtkScaleButton *button; GtkScaleButtonPrivate *priv; - GtkAdjustment *adj; + GtkAdjustment *adjustment; gint x, y, m, dx, dy, sx, sy, startoff; + gint min_slider_size; gdouble v; - GdkDisplay *display; GdkScreen *screen; + gboolean is_moved; + GdkDevice *device, *keyboard, *pointer; + is_moved = FALSE; button = GTK_SCALE_BUTTON (widget); priv = button->priv; - adj = priv->adjustment; + adjustment = priv->adjustment; - display = gtk_widget_get_display (widget); screen = gtk_widget_get_screen (widget); + gtk_widget_get_allocation (widget, &allocation); /* position roughly */ gtk_window_set_screen (GTK_WINDOW (priv->dock), screen); - gdk_window_get_origin (widget->window, &x, &y); - x += widget->allocation.x; - y += widget->allocation.y; + gdk_window_get_origin (gtk_widget_get_window (widget), + &x, &y); + x += allocation.x; + y += allocation.y; if (priv->orientation == GTK_ORIENTATION_VERTICAL) gtk_window_move (GTK_WINDOW (priv->dock), x, y - (SCALE_SIZE / 2)); @@ -919,28 +934,33 @@ gtk_scale_popup (GtkWidget *widget, gtk_widget_show_all (priv->dock); - gdk_window_get_origin (priv->dock->window, &dx, &dy); - dx += priv->dock->allocation.x; - dy += priv->dock->allocation.y; + gdk_window_get_origin (gtk_widget_get_window (priv->dock), + &dx, &dy); + gtk_widget_get_allocation (priv->dock, &dock_allocation); + dx += dock_allocation.x; + dy += dock_allocation.y; + - gdk_window_get_origin (priv->scale->window, &sx, &sy); - sx += priv->scale->allocation.x; - sy += priv->scale->allocation.y; + gdk_window_get_origin (gtk_widget_get_window (priv->scale), + &sx, &sy); + gtk_widget_get_allocation (priv->scale, &scale_allocation); + sx += scale_allocation.x; + sy += scale_allocation.y; priv->timeout = TRUE; /* position (needs widget to be shown already) */ - v = gtk_scale_button_get_value (button) / (adj->upper - adj->lower); + v = gtk_scale_button_get_value (button) / (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment)); + min_slider_size = gtk_range_get_min_slider_size (GTK_RANGE (priv->scale)); if (priv->orientation == GTK_ORIENTATION_VERTICAL) { startoff = sy - dy; - x += (widget->allocation.width - priv->dock->allocation.width) / 2; + x += (allocation.width - dock_allocation.width) / 2; y -= startoff; - y -= GTK_RANGE (priv->scale)->min_slider_size / 2; - m = priv->scale->allocation.height - - GTK_RANGE (priv->scale)->min_slider_size; + y -= min_slider_size / 2; + m = scale_allocation.height - min_slider_size; y -= m * (1.0 - v); } else @@ -948,16 +968,16 @@ gtk_scale_popup (GtkWidget *widget, startoff = sx - dx; x -= startoff; - y += (widget->allocation.height - priv->dock->allocation.height) / 2; - x -= GTK_RANGE (priv->scale)->min_slider_size / 2; - m = priv->scale->allocation.width - - GTK_RANGE (priv->scale)->min_slider_size; + y += (allocation.height - dock_allocation.height) / 2; + x -= min_slider_size / 2; + m = scale_allocation.width - min_slider_size; x -= m * v; } /* Make sure the dock stays inside the monitor */ if (event->type == GDK_BUTTON_PRESS) { + GtkAllocation d_allocation; int monitor; GdkEventButton *button_event = (GdkEventButton *) event; GdkRectangle rect; @@ -967,22 +987,38 @@ gtk_scale_popup (GtkWidget *widget, monitor = gdk_screen_get_monitor_at_point (screen, button_event->x_root, button_event->y_root); - gdk_screen_get_monitor_geometry (screen, monitor, &rect); + gdk_screen_get_monitor_workarea (screen, monitor, &rect); if (priv->orientation == GTK_ORIENTATION_VERTICAL) y += button_event->y; else x += button_event->x; + /* Move the dock, but set is_moved so we + * don't forward the first click later on, + * as it could make the scale go to the bottom */ + gtk_widget_get_allocation (d, &d_allocation); if (y < rect.y) - y = rect.y; - else if (y + d->allocation.height > rect.height + rect.y) - y = rect.y + rect.height - d->allocation.height; + { + y = rect.y; + is_moved = TRUE; + } + else if (y + d_allocation.height > rect.height + rect.y) + { + y = rect.y + rect.height - d_allocation.height; + is_moved = TRUE; + } if (x < rect.x) - x = rect.x; - else if (x + d->allocation.width > rect.width + rect.x) - x = rect.x + rect.width - d->allocation.width; + { + x = rect.x; + is_moved = TRUE; + } + else if (x + d_allocation.width > rect.width + rect.x) + { + x = rect.x + rect.width - d_allocation.width; + is_moved = TRUE; + } } gtk_window_move (GTK_WINDOW (priv->dock), x, y); @@ -990,56 +1026,73 @@ gtk_scale_popup (GtkWidget *widget, if (event->type == GDK_BUTTON_PRESS) GTK_WIDGET_CLASS (gtk_scale_button_parent_class)->button_press_event (widget, (GdkEventButton *) event); + device = gdk_event_get_device (event); + + if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) + { + keyboard = device; + pointer = gdk_device_get_associated_device (device); + } + else + { + pointer = device; + keyboard = gdk_device_get_associated_device (device); + } + /* grab focus */ - gtk_grab_add (priv->dock); + gtk_device_grab_add (priv->dock, pointer, TRUE); - if (gdk_pointer_grab (priv->dock->window, TRUE, - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK, NULL, NULL, time) - != GDK_GRAB_SUCCESS) + if (gdk_device_grab (pointer, gtk_widget_get_window (priv->dock), + GDK_OWNERSHIP_WINDOW, TRUE, + GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK, NULL, time) != GDK_GRAB_SUCCESS) { - gtk_grab_remove (priv->dock); + gtk_device_grab_remove (priv->dock, pointer); gtk_widget_hide (priv->dock); return FALSE; } - if (gdk_keyboard_grab (priv->dock->window, TRUE, time) != GDK_GRAB_SUCCESS) + if (gdk_device_grab (keyboard, gtk_widget_get_window (priv->dock), + GDK_OWNERSHIP_WINDOW, TRUE, + GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK, + NULL, time) != GDK_GRAB_SUCCESS) { - gdk_display_pointer_ungrab (display, time); - gtk_grab_remove (priv->dock); + gdk_device_ungrab (pointer, time); + gtk_device_grab_remove (priv->dock, pointer); gtk_widget_hide (priv->dock); return FALSE; } gtk_widget_grab_focus (priv->dock); + priv->grab_keyboard = keyboard; + priv->grab_pointer = pointer; - if (event->type == GDK_BUTTON_PRESS) + if (event->type == GDK_BUTTON_PRESS && !is_moved) { GdkEventButton *e; GdkEventButton *button_event = (GdkEventButton *) event; /* forward event to the slider */ e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event); - e->window = priv->scale->window; + e->window = gtk_widget_get_window (priv->scale); /* position: the X position isn't relevant, halfway will work just fine. * The vertical position should be *exactly* in the middle of the slider * of the scale; if we don't do that correctly, it'll move from its current * position, which means a position change on-click, which is bad. */ + gtk_widget_get_allocation (priv->scale, &scale_allocation); if (priv->orientation == GTK_ORIENTATION_VERTICAL) { - e->x = priv->scale->allocation.width / 2; - m = priv->scale->allocation.height - - GTK_RANGE (priv->scale)->min_slider_size; - e->y = ((1.0 - v) * m) + GTK_RANGE (priv->scale)->min_slider_size / 2; + e->x = scale_allocation.width / 2; + m = scale_allocation.height - min_slider_size; + e->y = ((1.0 - v) * m) + min_slider_size / 2; } else { - e->y = priv->scale->allocation.height / 2; - m = priv->scale->allocation.width - - GTK_RANGE (priv->scale)->min_slider_size; - e->x = (v * m) + GTK_RANGE (priv->scale)->min_slider_size / 2; + e->y = scale_allocation.height / 2; + m = scale_allocation.width - min_slider_size; + e->x = (v * m) + min_slider_size / 2; } gtk_widget_event (priv->scale, (GdkEvent *) e); @@ -1066,8 +1119,21 @@ gtk_scale_button_popup (GtkWidget *widget) { GdkEvent *ev; - ev = gdk_event_new (GDK_KEY_RELEASE); - gtk_scale_popup (widget, ev, GDK_CURRENT_TIME); + /* This is a callback for a keybinding signal, + * current event should be the key event that + * triggered it. + */ + ev = gtk_get_current_event (); + + if (ev->type != GDK_KEY_PRESS && + ev->type != GDK_KEY_RELEASE) + { + gdk_event_free (ev); + ev = gdk_event_new (GDK_KEY_RELEASE); + ev->key.time = GDK_CURRENT_TIME; + } + + gtk_scale_popup (widget, ev, ev->key.time); gdk_event_free (ev); } @@ -1075,33 +1141,44 @@ static gboolean gtk_scale_button_key_release (GtkWidget *widget, GdkEventKey *event) { - return gtk_bindings_activate_event (GTK_OBJECT (widget), event); + return gtk_bindings_activate_event (G_OBJECT (widget), event); } /* This is called when the grab is broken for * either the dock, or the scale itself */ static void gtk_scale_button_grab_notify (GtkScaleButton *button, - gboolean was_grabbed) + gboolean was_grabbed) { - GdkDisplay *display; GtkScaleButtonPrivate *priv; - - if (was_grabbed != FALSE) - return; + GtkWidget *toplevel, *grab_widget; + GtkWindowGroup *group; priv = button->priv; - if (!GTK_WIDGET_HAS_GRAB (priv->dock)) + if (!priv->grab_pointer || + !gtk_widget_device_is_shadowed (GTK_WIDGET (button), priv->grab_pointer)) return; - if (gtk_widget_is_ancestor (gtk_grab_get_current (), priv->dock)) + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button)); + + if (GTK_IS_WINDOW (toplevel)) + group = gtk_window_get_group (GTK_WINDOW (toplevel)); + else + group = gtk_window_get_group (NULL); + + grab_widget = gtk_window_group_get_current_device_grab (group, priv->grab_pointer); + + if (grab_widget && + gtk_widget_is_ancestor (grab_widget, priv->dock)) return; - display = gtk_widget_get_display (priv->dock); - gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME); - gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME); - gtk_grab_remove (priv->dock); + gdk_device_ungrab (priv->grab_keyboard, GDK_CURRENT_TIME); + gdk_device_ungrab (priv->grab_pointer, GDK_CURRENT_TIME); + gtk_device_grab_remove (priv->dock, priv->grab_pointer); + + priv->grab_keyboard = NULL; + priv->grab_pointer = NULL; /* hide again */ gtk_widget_hide (priv->dock); @@ -1117,7 +1194,7 @@ cb_button_timeout (gpointer user_data) { GtkScaleButton *button; GtkScaleButtonPrivate *priv; - GtkAdjustment *adj; + GtkAdjustment *adjustment; gdouble val; gboolean res = TRUE; @@ -1127,19 +1204,19 @@ cb_button_timeout (gpointer user_data) if (priv->click_id == 0) return FALSE; - adj = priv->adjustment; + adjustment = priv->adjustment; val = gtk_scale_button_get_value (button); val += priv->direction; - if (val <= adj->lower) + if (val <= gtk_adjustment_get_lower (adjustment)) { res = FALSE; - val = adj->lower; + val = gtk_adjustment_get_lower (adjustment); } - else if (val > adj->upper) + else if (val > gtk_adjustment_get_upper (adjustment)) { res = FALSE; - val = adj->upper; + val = gtk_adjustment_get_upper (adjustment); } gtk_scale_button_set_value (button, val); @@ -1159,19 +1236,19 @@ cb_button_press (GtkWidget *widget, { GtkScaleButton *button; GtkScaleButtonPrivate *priv; - GtkAdjustment *adj; + GtkAdjustment *adjustment; button = GTK_SCALE_BUTTON (user_data); priv = button->priv; - adj = priv->adjustment; + adjustment = priv->adjustment; if (priv->click_id != 0) g_source_remove (priv->click_id); - if (widget == button->plus_button) - priv->direction = fabs (adj->page_increment); + if (widget == priv->plus_button) + priv->direction = fabs (gtk_adjustment_get_page_increment (adjustment)); else - priv->direction = - fabs (adj->page_increment); + priv->direction = - fabs (gtk_adjustment_get_page_increment (adjustment)); priv->click_id = gdk_threads_add_timeout (priv->click_timeout, cb_button_timeout, @@ -1213,7 +1290,7 @@ cb_dock_grab_notify (GtkWidget *widget, static gboolean cb_dock_grab_broken_event (GtkWidget *widget, - gboolean was_grabbed, + gboolean was_grabbed, gpointer user_data) { GtkScaleButton *button = (GtkScaleButton *) user_data; @@ -1223,32 +1300,31 @@ cb_dock_grab_broken_event (GtkWidget *widget, return FALSE; } -/* - * Scale callbacks. - */ +/* Scale callbacks */ static void gtk_scale_button_release_grab (GtkScaleButton *button, - GdkEventButton *event) + GdkEventButton *event) { GdkEventButton *e; - GdkDisplay *display; GtkScaleButtonPrivate *priv; priv = button->priv; /* ungrab focus */ - display = gtk_widget_get_display (GTK_WIDGET (button)); - gdk_display_keyboard_ungrab (display, event->time); - gdk_display_pointer_ungrab (display, event->time); - gtk_grab_remove (priv->dock); + gdk_device_ungrab (priv->grab_keyboard, event->time); + gdk_device_ungrab (priv->grab_pointer, event->time); + gtk_device_grab_remove (priv->dock, priv->grab_pointer); + + priv->grab_keyboard = NULL; + priv->grab_pointer = NULL; /* hide again */ gtk_widget_hide (priv->dock); priv->timeout = FALSE; e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event); - e->window = GTK_WIDGET (button)->window; + e->window = gtk_widget_get_window (GTK_WIDGET (button)); e->type = GDK_BUTTON_RELEASE; gtk_widget_event (GTK_WIDGET (button), (GdkEvent *) e); e->window = event->window; @@ -1276,16 +1352,17 @@ gtk_scale_button_popdown (GtkWidget *widget) { GtkScaleButton *button; GtkScaleButtonPrivate *priv; - GdkDisplay *display; button = GTK_SCALE_BUTTON (widget); priv = button->priv; /* ungrab focus */ - display = gtk_widget_get_display (widget); - gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME); - gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME); - gtk_grab_remove (priv->dock); + gdk_device_ungrab (priv->grab_keyboard, GDK_CURRENT_TIME); + gdk_device_ungrab (priv->grab_pointer, GDK_CURRENT_TIME); + gtk_device_grab_remove (priv->dock, priv->grab_pointer); + + priv->grab_keyboard = NULL; + priv->grab_pointer = NULL; /* hide again */ gtk_widget_hide (priv->dock); @@ -1297,16 +1374,16 @@ cb_dock_key_release (GtkWidget *widget, GdkEventKey *event, gpointer user_data) { - if (event->keyval == GDK_Escape) + if (event->keyval == GDK_KEY_Escape) { gtk_scale_button_popdown (GTK_WIDGET (user_data)); return TRUE; } - if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event)) + if (!gtk_bindings_activate_event (G_OBJECT (widget), event)) { /* The popup hasn't managed the event, pass onto the button */ - gtk_bindings_activate_event (GTK_OBJECT (user_data), event); + gtk_bindings_activate_event (G_OBJECT (user_data), event); } return TRUE; @@ -1326,43 +1403,32 @@ cb_scale_grab_notify (GtkWidget *widget, * Scale stuff. */ -#define GTK_TYPE_SCALE_BUTTON_VSCALE (_gtk_scale_button_vscale_get_type ()) -#define GTK_SCALE_BUTTON_VSCALE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SCALE_BUTTON_VSCALE, GtkScaleButtonVScale)) -#define GTK_IS_SCALE_BUTTON_VSCALE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SCALE_BUTTON_VSCALE)) - -typedef struct _GtkScaleButtonVScale { - GtkVScale parent; - GtkScaleButton *button; -} GtkScaleButtonVScale; - -typedef struct _GtkScaleButtonVScaleClass { - GtkVScaleClass parent_class; -} GtkScaleButtonVScaleClass; - -#define GTK_TYPE_SCALE_BUTTON_HSCALE (_gtk_scale_button_hscale_get_type ()) -#define GTK_SCALE_BUTTON_HSCALE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SCALE_BUTTON_HSCALE, GtkScaleButtonHScale)) -#define GTK_IS_SCALE_BUTTON_HSCALE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SCALE_BUTTON_HSCALE)) +#define GTK_TYPE_SCALE_BUTTON_SCALE (_gtk_scale_button_scale_get_type ()) +#define GTK_SCALE_BUTTON_SCALE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SCALE_BUTTON_SCALE, GtkScaleButtonScale)) +#define GTK_IS_SCALE_BUTTON_SCALE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SCALE_BUTTON_SCALE)) -typedef struct _GtkScaleButtonHScale { - GtkVScale parent; +typedef struct _GtkScaleButtonScale +{ + GtkScale parent_instance; GtkScaleButton *button; -} GtkScaleButtonHScale; +} GtkScaleButtonScale; -typedef struct _GtkScaleButtonHScaleClass { - GtkVScaleClass parent_class; -} GtkScaleButtonHScaleClass; +typedef struct _GtkScaleButtonScaleClass +{ + GtkScaleClass parent_class; +} GtkScaleButtonScaleClass; static gboolean gtk_scale_button_scale_press (GtkWidget *widget, GdkEventButton *event); static gboolean gtk_scale_button_scale_release (GtkWidget *widget, GdkEventButton *event); -G_DEFINE_TYPE (GtkScaleButtonVScale, _gtk_scale_button_vscale, GTK_TYPE_VSCALE) +GType _gtk_scale_button_scale_get_type (void); -G_DEFINE_TYPE (GtkScaleButtonHScale, _gtk_scale_button_hscale, GTK_TYPE_HSCALE) +G_DEFINE_TYPE (GtkScaleButtonScale, _gtk_scale_button_scale, GTK_TYPE_SCALE) static void -_gtk_scale_button_vscale_class_init (GtkScaleButtonVScaleClass *klass) +_gtk_scale_button_scale_class_init (GtkScaleButtonScaleClass *klass) { GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass); GtkRangeClass *gtkrange_class = GTK_RANGE_CLASS (klass); @@ -1373,121 +1439,62 @@ _gtk_scale_button_vscale_class_init (GtkScaleButtonVScaleClass *klass) } static void -_gtk_scale_button_hscale_class_init (GtkScaleButtonHScaleClass *klass) -{ - GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass); - GtkRangeClass *gtkrange_class = GTK_RANGE_CLASS (klass); - - gtkwidget_class->button_press_event = gtk_scale_button_scale_press; - gtkwidget_class->button_release_event = gtk_scale_button_scale_release; - gtkrange_class->value_changed = gtk_scale_button_scale_value_changed; -} - -static void -_gtk_scale_button_vscale_init (GtkScaleButtonVScale *scale) -{ -} - -static void -_gtk_scale_button_hscale_init (GtkScaleButtonHScale *scale) +_gtk_scale_button_scale_init (GtkScaleButtonScale *scale) { } static GtkWidget * -gtk_scale_button_scale_box_new (GtkScaleButton *button) +gtk_scale_button_scale_new (GtkScaleButton *button) { GtkScaleButtonPrivate *priv = button->priv; - GtkScaleButtonVScale *scale; - GtkWidget *box; + GtkScaleButtonScale *scale; - if (priv->orientation == GTK_ORIENTATION_VERTICAL) - { - box = gtk_vbox_new (FALSE, 0); + scale = g_object_new (GTK_TYPE_SCALE_BUTTON_SCALE, + "orientation", priv->orientation, + "adjustment", priv->adjustment, + "draw-value", FALSE, + NULL); - scale = g_object_new (GTK_TYPE_SCALE_BUTTON_VSCALE, NULL); - priv->scale = GTK_WIDGET (scale); + scale->button = button; - gtk_widget_set_size_request (priv->scale, -1, SCALE_SIZE); - gtk_range_set_inverted (GTK_RANGE (priv->scale), TRUE); + g_signal_connect (scale, "grab-notify", + G_CALLBACK (cb_scale_grab_notify), button); - gtk_box_pack_start (GTK_BOX (box), button->plus_button, TRUE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), priv->scale, TRUE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), button->minus_button, TRUE, FALSE, 0); + if (priv->orientation == GTK_ORIENTATION_VERTICAL) + { + gtk_widget_set_size_request (GTK_WIDGET (scale), -1, SCALE_SIZE); + gtk_range_set_inverted (GTK_RANGE (scale), TRUE); } else { - box = gtk_hbox_new (FALSE, 0); - - scale = g_object_new (GTK_TYPE_SCALE_BUTTON_HSCALE, NULL); - priv->scale = GTK_WIDGET (scale); - - gtk_widget_set_size_request (priv->scale, SCALE_SIZE, -1); - - gtk_box_pack_start (GTK_BOX (box), button->minus_button, TRUE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), priv->scale, TRUE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), button->plus_button, TRUE, FALSE, 0); + gtk_widget_set_size_request (GTK_WIDGET (scale), SCALE_SIZE, -1); + gtk_range_set_inverted (GTK_RANGE (scale), FALSE); } - gtk_scale_set_draw_value (GTK_SCALE (priv->scale), FALSE); - gtk_range_set_adjustment (GTK_RANGE (scale), - GTK_ADJUSTMENT (priv->adjustment)); - scale->button = button; - - g_signal_connect (priv->scale, "grab-notify", - G_CALLBACK (cb_scale_grab_notify), button); - - /* FIXME: without this, the popup window appears as a square - * after changing the orientation - */ - gtk_window_resize (GTK_WINDOW (priv->dock), 1, 1); - - return box; + return GTK_WIDGET (scale); } static gboolean gtk_scale_button_scale_press (GtkWidget *widget, GdkEventButton *event) { - GtkScaleButtonPrivate *priv; - GtkWidgetClass *widget_class; - - if (GTK_IS_SCALE_BUTTON_VSCALE (widget)) - { - priv = GTK_SCALE_BUTTON_VSCALE (widget)->button->priv; - widget_class = GTK_WIDGET_CLASS (_gtk_scale_button_vscale_parent_class); - } - else - { - priv = GTK_SCALE_BUTTON_HSCALE (widget)->button->priv; - widget_class = GTK_WIDGET_CLASS (_gtk_scale_button_hscale_parent_class); - } + GtkScaleButtonPrivate *priv = GTK_SCALE_BUTTON_SCALE (widget)->button->priv; /* the scale will grab input; if we have input grabbed, all goes - * horribly wrong, so let's not do that. */ - gtk_grab_remove (priv->dock); + * horribly wrong, so let's not do that. + */ + gtk_device_grab_remove (priv->dock, event->device); - return widget_class->button_press_event (widget, event); + return GTK_WIDGET_CLASS (_gtk_scale_button_scale_parent_class)->button_press_event (widget, event); } static gboolean gtk_scale_button_scale_release (GtkWidget *widget, GdkEventButton *event) { - GtkScaleButton *button; - GtkWidgetClass *widget_class; + GtkScaleButton *button = GTK_SCALE_BUTTON_SCALE (widget)->button; gboolean res; - if (GTK_IS_SCALE_BUTTON_VSCALE (widget)) - { - button = GTK_SCALE_BUTTON_VSCALE (widget)->button; - widget_class = GTK_WIDGET_CLASS (_gtk_scale_button_vscale_parent_class); - } - else - { - button = GTK_SCALE_BUTTON_HSCALE (widget)->button; - widget_class = GTK_WIDGET_CLASS (_gtk_scale_button_hscale_parent_class); - } - if (button->priv->timeout) { /* if we did a quick click, leave the window open; else, hide it */ @@ -1495,7 +1502,7 @@ gtk_scale_button_scale_release (GtkWidget *widget, { gtk_scale_button_release_grab (button, event); - widget_class->button_release_event (widget, event); + GTK_WIDGET_CLASS (_gtk_scale_button_scale_parent_class)->button_release_event (widget, event); return TRUE; } @@ -1503,7 +1510,7 @@ gtk_scale_button_scale_release (GtkWidget *widget, button->priv->timeout = FALSE; } - res = widget_class->button_release_event (widget, event); + res = GTK_WIDGET_CLASS (_gtk_scale_button_scale_parent_class)->button_release_event (widget, event); /* the scale will release input; right after that, we *have to* grab * it back so we can catch out-of-scale clicks and hide the popup, @@ -1511,7 +1518,7 @@ gtk_scale_button_scale_release (GtkWidget *widget, * find that, so we do this complex 'first-call-parent-then-do-actual- * action' thingy... */ - gtk_grab_add (button->priv->dock); + gtk_device_grab_add (button->priv->dock, event->device, TRUE); return res; } @@ -1520,8 +1527,7 @@ static void gtk_scale_button_update_icon (GtkScaleButton *button) { GtkScaleButtonPrivate *priv; - GtkRange *range; - GtkAdjustment *adj; + GtkAdjustment *adjustment; gdouble value; const gchar *name; guint num_icons; @@ -1531,8 +1537,8 @@ gtk_scale_button_update_icon (GtkScaleButton *button) if (!priv->icon_list || priv->icon_list[0] == '\0') { gtk_image_set_from_stock (GTK_IMAGE (priv->image), - GTK_STOCK_MISSING_IMAGE, - priv->size); + GTK_STOCK_MISSING_IMAGE, + priv->size); return; } @@ -1542,37 +1548,37 @@ gtk_scale_button_update_icon (GtkScaleButton *button) if (num_icons == 1) { gtk_image_set_from_icon_name (GTK_IMAGE (priv->image), - priv->icon_list[0], - priv->size); + priv->icon_list[0], + priv->size); return; } - range = GTK_RANGE (priv->scale); - adj = priv->adjustment; + adjustment = priv->adjustment; value = gtk_scale_button_get_value (button); /* The 2-icons special case */ if (num_icons == 2) { gdouble limit; - limit = (adj->upper - adj->lower) / 2 + adj->lower; + + limit = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment)) / 2 + gtk_adjustment_get_lower (adjustment); if (value < limit) - name = priv->icon_list[0]; + name = priv->icon_list[0]; else - name = priv->icon_list[1]; + name = priv->icon_list[1]; gtk_image_set_from_icon_name (GTK_IMAGE (priv->image), - name, - priv->size); + name, + priv->size); return; } /* With 3 or more icons */ - if (value == adj->lower) + if (value == gtk_adjustment_get_lower (adjustment)) { name = priv->icon_list[0]; } - else if (value == adj->upper) + else if (value == gtk_adjustment_get_upper (adjustment)) { name = priv->icon_list[1]; } @@ -1581,28 +1587,23 @@ gtk_scale_button_update_icon (GtkScaleButton *button) gdouble step; guint i; - step = (adj->upper - adj->lower) / (num_icons - 2); - i = (guint) ((value - adj->lower) / step) + 2; + step = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment)) / (num_icons - 2); + i = (guint) ((value - gtk_adjustment_get_lower (adjustment)) / step) + 2; g_assert (i < num_icons); name = priv->icon_list[i]; } gtk_image_set_from_icon_name (GTK_IMAGE (priv->image), - name, - priv->size); + name, + priv->size); } static void gtk_scale_button_scale_value_changed (GtkRange *range) { - GtkScaleButton *button; + GtkScaleButton *button = GTK_SCALE_BUTTON_SCALE (range)->button; gdouble value; - if (GTK_IS_SCALE_BUTTON_VSCALE (range)) - button = GTK_SCALE_BUTTON_VSCALE (range)->button; - else - button = GTK_SCALE_BUTTON_HSCALE (range)->button; - value = gtk_range_get_value (range); gtk_scale_button_update_icon (button); @@ -1610,6 +1611,3 @@ gtk_scale_button_scale_value_changed (GtkRange *range) g_signal_emit (button, signals[VALUE_CHANGED], 0, value); g_object_notify (G_OBJECT (button), "value"); } - -#define __GTK_SCALE_BUTTON_C__ -#include "gtkaliasdef.c"