2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2007-05-19 23:08:02 +00:00
|
|
|
* Copyright (C) 2005 Ronald S. Bultje
|
|
|
|
* Copyright (C) 2006, 2007 Christian Persch
|
|
|
|
* Copyright (C) 2006 Jan Arne Petersen
|
|
|
|
* Copyright (C) 2005-2007 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* - Ronald S. Bultje <rbultje@ronald.bitfreak.net>
|
|
|
|
* - Bastien Nocera <bnocera@redhat.com>
|
|
|
|
* - Jan Arne Petersen <jpetersen@jpetersen.org>
|
|
|
|
* - Christian Persch <chpe@svn.gnome.org>
|
|
|
|
*
|
|
|
|
* 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/>.
|
2007-05-19 23:08:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified by the GTK+ Team and others 2007. 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
|
2008-06-26 17:14:27 +00:00
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
2007-05-19 23:08:02 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2012-03-03 18:41:55 +00:00
|
|
|
#include "gtkscalebutton.h"
|
|
|
|
|
2008-10-01 11:02:51 +00:00
|
|
|
#ifndef _WIN32
|
2007-05-19 23:08:02 +00:00
|
|
|
#define _GNU_SOURCE
|
2008-10-01 11:02:51 +00:00
|
|
|
#endif
|
2007-05-19 23:08:02 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-03-03 18:41:55 +00:00
|
|
|
#include "gtkadjustment.h"
|
2007-05-19 23:08:02 +00:00
|
|
|
#include "gtkbindings.h"
|
|
|
|
#include "gtkframe.h"
|
2009-02-19 15:10:34 +00:00
|
|
|
#include "gtkmain.h"
|
2007-05-19 23:08:02 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2009-02-19 15:10:34 +00:00
|
|
|
#include "gtkorientable.h"
|
2007-06-10 01:26:28 +00:00
|
|
|
#include "gtkprivate.h"
|
2009-02-19 15:10:34 +00:00
|
|
|
#include "gtkscale.h"
|
|
|
|
#include "gtkstock.h"
|
2011-08-28 05:54:55 +00:00
|
|
|
#include "gtkbox.h"
|
2009-02-19 15:10:34 +00:00
|
|
|
#include "gtkwindow.h"
|
2011-01-04 19:51:19 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
2009-02-19 15:10:34 +00:00
|
|
|
#include "gtkintl.h"
|
2011-06-29 02:45:42 +00:00
|
|
|
#include "a11y/gtkscalebuttonaccessible.h"
|
2010-05-15 22:32:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
#define SCALE_SIZE 100
|
|
|
|
#define CLICK_TIMEOUT 250
|
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
enum
|
|
|
|
{
|
2007-05-19 23:08:02 +00:00
|
|
|
VALUE_CHANGED,
|
|
|
|
POPUP,
|
|
|
|
POPDOWN,
|
2007-06-10 15:32:02 +00:00
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
enum
|
|
|
|
{
|
2007-05-19 23:08:02 +00:00
|
|
|
PROP_0,
|
2008-06-26 17:14:27 +00:00
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
PROP_ORIENTATION,
|
2007-05-19 23:08:02 +00:00
|
|
|
PROP_VALUE,
|
|
|
|
PROP_SIZE,
|
2007-06-10 01:26:28 +00:00
|
|
|
PROP_ADJUSTMENT,
|
|
|
|
PROP_ICONS
|
2007-05-19 23:08:02 +00:00
|
|
|
};
|
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
struct _GtkScaleButtonPrivate
|
|
|
|
{
|
2010-07-08 01:13:10 +00:00
|
|
|
GtkWidget *plus_button;
|
|
|
|
GtkWidget *minus_button;
|
2007-06-10 15:32:02 +00:00
|
|
|
GtkWidget *dock;
|
2009-02-19 15:10:34 +00:00
|
|
|
GtkWidget *box;
|
2007-06-10 15:32:02 +00:00
|
|
|
GtkWidget *scale;
|
|
|
|
GtkWidget *image;
|
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
GtkIconSize size;
|
2008-06-27 09:33:32 +00:00
|
|
|
GtkOrientation orientation;
|
2008-06-26 17:14:27 +00:00
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
guint click_id;
|
2007-06-10 15:32:02 +00:00
|
|
|
gint click_timeout;
|
|
|
|
guint timeout : 1;
|
2007-05-19 23:08:02 +00:00
|
|
|
gdouble direction;
|
|
|
|
guint32 pop_time;
|
2008-06-26 17:14:27 +00:00
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
gchar **icon_list;
|
2008-06-27 09:33:32 +00:00
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDevice *grab_pointer;
|
|
|
|
GdkDevice *grab_keyboard;
|
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
GtkAdjustment *adjustment; /* needed because it must be settable in init() */
|
2007-06-10 15:32:02 +00:00
|
|
|
};
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
static GObject* gtk_scale_button_constructor (GType type,
|
|
|
|
guint n_construct_properties,
|
|
|
|
GObjectConstructParam *construct_params);
|
2007-05-19 23:08:02 +00:00
|
|
|
static void gtk_scale_button_dispose (GObject *object);
|
2007-06-10 15:32:02 +00:00
|
|
|
static void gtk_scale_button_finalize (GObject *object);
|
2007-05-19 23:08:02 +00:00
|
|
|
static void gtk_scale_button_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_scale_button_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2009-03-18 21:19:07 +00:00
|
|
|
static void gtk_scale_button_set_orientation_private (GtkScaleButton *button,
|
|
|
|
GtkOrientation orientation);
|
2007-05-19 23:08:02 +00:00
|
|
|
static gboolean gtk_scale_button_scroll (GtkWidget *widget,
|
|
|
|
GdkEventScroll *event);
|
|
|
|
static void gtk_scale_button_screen_changed (GtkWidget *widget,
|
|
|
|
GdkScreen *previous_screen);
|
|
|
|
static gboolean gtk_scale_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static gboolean gtk_scale_button_key_release (GtkWidget *widget,
|
|
|
|
GdkEventKey *event);
|
2008-07-03 13:13:23 +00:00
|
|
|
static void gtk_scale_button_popup (GtkWidget *widget);
|
|
|
|
static void gtk_scale_button_popdown (GtkWidget *widget);
|
2007-05-19 23:08:02 +00:00
|
|
|
static gboolean cb_dock_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean cb_dock_key_release (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean cb_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean cb_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data);
|
|
|
|
static void cb_dock_grab_notify (GtkWidget *widget,
|
|
|
|
gboolean was_grabbed,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean cb_dock_grab_broken_event (GtkWidget *widget,
|
|
|
|
gboolean was_grabbed,
|
|
|
|
gpointer user_data);
|
|
|
|
static void cb_scale_grab_notify (GtkWidget *widget,
|
|
|
|
gboolean was_grabbed,
|
|
|
|
gpointer user_data);
|
|
|
|
static void gtk_scale_button_update_icon (GtkScaleButton *button);
|
|
|
|
static void gtk_scale_button_scale_value_changed(GtkRange *range);
|
|
|
|
|
2009-01-13 15:24:03 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkScaleButton, gtk_scale_button, GTK_TYPE_BUTTON,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
|
|
|
|
NULL))
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2009-01-13 15:24:03 +00:00
|
|
|
static guint signals[LAST_SIGNAL] = { 0, };
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2013-03-23 11:17:15 +00:00
|
|
|
/*
|
|
|
|
* ScaleButtonScale forward declarations
|
|
|
|
*/
|
|
|
|
#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))
|
|
|
|
GType _gtk_scale_button_scale_get_type (void);
|
|
|
|
|
|
|
|
typedef struct _GtkScaleButtonScale
|
|
|
|
{
|
|
|
|
GtkScale parent_instance;
|
|
|
|
GtkScaleButton *button;
|
|
|
|
} GtkScaleButtonScale;
|
|
|
|
|
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
static void
|
|
|
|
gtk_scale_button_class_init (GtkScaleButtonClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2007-06-10 15:32:02 +00:00
|
|
|
GtkBindingSet *binding_set;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GtkScaleButtonPrivate));
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
gobject_class->constructor = gtk_scale_button_constructor;
|
2007-06-10 15:32:02 +00:00
|
|
|
gobject_class->finalize = gtk_scale_button_finalize;
|
2007-05-19 23:08:02 +00:00
|
|
|
gobject_class->dispose = gtk_scale_button_dispose;
|
|
|
|
gobject_class->set_property = gtk_scale_button_set_property;
|
|
|
|
gobject_class->get_property = gtk_scale_button_get_property;
|
2008-06-26 17:14:27 +00:00
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
widget_class->button_press_event = gtk_scale_button_press;
|
|
|
|
widget_class->key_release_event = gtk_scale_button_key_release;
|
|
|
|
widget_class->scroll_event = gtk_scale_button_scroll;
|
|
|
|
widget_class->screen_changed = gtk_scale_button_screen_changed;
|
|
|
|
|
2008-06-30 23:41:10 +00:00
|
|
|
/**
|
|
|
|
* GtkScaleButton:orientation:
|
|
|
|
*
|
|
|
|
* The orientation of the #GtkScaleButton's popup window.
|
|
|
|
*
|
2009-02-19 15:10:34 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2008-06-30 23:41:10 +00:00
|
|
|
* Since: 2.14
|
|
|
|
**/
|
2009-01-13 15:24:03 +00:00
|
|
|
g_object_class_override_property (gobject_class,
|
|
|
|
PROP_ORIENTATION,
|
|
|
|
"orientation");
|
2008-06-27 09:33:32 +00:00
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_VALUE,
|
|
|
|
g_param_spec_double ("value",
|
|
|
|
P_("Value"),
|
|
|
|
P_("The value of the scale"),
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0,
|
2007-06-10 01:26:28 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_SIZE,
|
|
|
|
g_param_spec_enum ("size",
|
|
|
|
P_("Icon size"),
|
|
|
|
P_("The icon size"),
|
|
|
|
GTK_TYPE_ICON_SIZE,
|
|
|
|
GTK_ICON_SIZE_SMALL_TOOLBAR,
|
2007-06-10 01:26:28 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ADJUSTMENT,
|
|
|
|
g_param_spec_object ("adjustment",
|
|
|
|
P_("Adjustment"),
|
|
|
|
P_("The GtkAdjustment that contains the current value of this scale button object"),
|
|
|
|
GTK_TYPE_ADJUSTMENT,
|
2007-06-10 01:26:28 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2007-06-10 01:26:28 +00:00
|
|
|
/**
|
|
|
|
* GtkScaleButton:icons:
|
|
|
|
*
|
2008-06-26 17:14:27 +00:00
|
|
|
* 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
|
2007-06-10 01:26:28 +00:00
|
|
|
* range of values.
|
|
|
|
*
|
2008-06-26 17:14:27 +00:00
|
|
|
* 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
|
2007-06-10 01:26:28 +00:00
|
|
|
* 50% of the scale, and the second one for the top 50%.
|
|
|
|
*
|
2008-06-26 17:14:27 +00:00
|
|
|
* It is recommended to use at least 3 icons so that the
|
|
|
|
* #GtkScaleButton reflects the current value of the scale
|
2007-06-10 01:26:28 +00:00
|
|
|
* 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));
|
2007-07-16 15:00:05 +00:00
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
/**
|
|
|
|
* GtkScaleButton::value-changed:
|
2007-07-16 15:00:05 +00:00
|
|
|
* @button: the object which received the signal
|
|
|
|
* @value: the new value
|
2007-05-19 23:08:02 +00:00
|
|
|
*
|
2007-07-16 15:00:05 +00:00
|
|
|
* The ::value-changed signal is emitted when the value field has
|
|
|
|
* changed.
|
2007-05-19 23:08:02 +00:00
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
*/
|
|
|
|
signals[VALUE_CHANGED] =
|
|
|
|
g_signal_new (I_("value-changed"),
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkScaleButtonClass, value_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
_gtk_marshal_VOID__DOUBLE,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_DOUBLE);
|
2008-06-26 17:14:27 +00:00
|
|
|
|
2007-07-16 15:00:05 +00:00
|
|
|
/**
|
|
|
|
* GtkScaleButton::popup:
|
|
|
|
* @button: the object which received the signal
|
|
|
|
*
|
2008-06-26 17:14:27 +00:00
|
|
|
* The ::popup signal is a
|
|
|
|
* <link linkend="keybinding-signals">keybinding signal</link>
|
2007-07-16 15:00:05 +00:00
|
|
|
* which gets emitted to popup the scale widget.
|
|
|
|
*
|
|
|
|
* The default bindings for this signal are Space, Enter and Return.
|
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
*/
|
2007-05-19 23:08:02 +00:00
|
|
|
signals[POPUP] =
|
2008-07-21 09:48:20 +00:00
|
|
|
g_signal_new_class_handler (I_("popup"),
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_CALLBACK (gtk_scale_button_popup),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2007-07-16 15:00:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkScaleButton::popdown:
|
|
|
|
* @button: the object which received the signal
|
|
|
|
*
|
2008-06-26 17:14:27 +00:00
|
|
|
* The ::popdown signal is a
|
|
|
|
* <link linkend="keybinding-signals">keybinding signal</link>
|
2007-07-16 15:00:05 +00:00
|
|
|
* which gets emitted to popdown the scale widget.
|
|
|
|
*
|
|
|
|
* The default binding for this signal is Escape.
|
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
*/
|
2007-05-19 23:08:02 +00:00
|
|
|
signals[POPDOWN] =
|
2008-07-21 09:48:20 +00:00
|
|
|
g_signal_new_class_handler (I_("popdown"),
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_CALLBACK (gtk_scale_button_popdown),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
/* Key bindings */
|
|
|
|
binding_set = gtk_binding_set_by_class (widget_class);
|
|
|
|
|
2010-09-08 17:35:51 +00:00
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
|
2007-05-19 23:08:02 +00:00
|
|
|
"popup", 0);
|
2010-09-08 17:35:51 +00:00
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
|
2008-02-12 15:51:09 +00:00
|
|
|
"popup", 0);
|
2010-09-08 17:35:51 +00:00
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
|
2007-05-19 23:08:02 +00:00
|
|
|
"popup", 0);
|
2010-09-08 17:35:51 +00:00
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
|
2007-05-19 23:08:02 +00:00
|
|
|
"popup", 0);
|
2010-09-08 17:35:51 +00:00
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
|
2007-05-19 23:08:02 +00:00
|
|
|
"popup", 0);
|
2010-09-08 17:35:51 +00:00
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
|
2007-05-19 23:08:02 +00:00
|
|
|
"popdown", 0);
|
2011-06-29 02:45:42 +00:00
|
|
|
|
2013-03-23 11:17:15 +00:00
|
|
|
/* Bind class to template
|
|
|
|
*/
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class,
|
|
|
|
"/org/gtk/libgtk/gtkscalebutton.ui");
|
|
|
|
|
|
|
|
gtk_widget_class_bind_child_internal (widget_class, GtkScaleButtonPrivate, plus_button);
|
|
|
|
gtk_widget_class_bind_child_internal (widget_class, GtkScaleButtonPrivate, minus_button);
|
|
|
|
gtk_widget_class_bind_child (widget_class, GtkScaleButtonPrivate, dock);
|
|
|
|
gtk_widget_class_bind_child (widget_class, GtkScaleButtonPrivate, box);
|
|
|
|
gtk_widget_class_bind_child (widget_class, GtkScaleButtonPrivate, scale);
|
|
|
|
gtk_widget_class_bind_child (widget_class, GtkScaleButtonPrivate, image);
|
|
|
|
gtk_widget_class_bind_child (widget_class, GtkScaleButtonPrivate, adjustment);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_callback (widget_class, cb_dock_button_press);
|
|
|
|
gtk_widget_class_bind_callback (widget_class, cb_dock_key_release);
|
|
|
|
gtk_widget_class_bind_callback (widget_class, cb_dock_grab_notify);
|
|
|
|
gtk_widget_class_bind_callback (widget_class, cb_dock_grab_broken_event);
|
|
|
|
gtk_widget_class_bind_callback (widget_class, cb_button_press);
|
|
|
|
gtk_widget_class_bind_callback (widget_class, cb_button_release);
|
|
|
|
gtk_widget_class_bind_callback (widget_class, cb_scale_grab_notify);
|
|
|
|
|
2011-06-29 02:45:42 +00:00
|
|
|
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCALE_BUTTON_ACCESSIBLE);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_scale_button_init (GtkScaleButton *button)
|
|
|
|
{
|
|
|
|
GtkScaleButtonPrivate *priv;
|
|
|
|
|
2010-07-08 01:13:10 +00:00
|
|
|
button->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
|
|
|
|
GTK_TYPE_SCALE_BUTTON,
|
|
|
|
GtkScaleButtonPrivate);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
priv->timeout = FALSE;
|
|
|
|
priv->click_id = 0;
|
|
|
|
priv->click_timeout = CLICK_TIMEOUT;
|
2008-06-30 23:41:10 +00:00
|
|
|
priv->orientation = GTK_ORIENTATION_VERTICAL;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2013-03-23 11:17:15 +00:00
|
|
|
g_type_ensure (GTK_TYPE_SCALE_BUTTON_SCALE);
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (button));
|
|
|
|
|
|
|
|
/* Assign GtkScaleButtonScale pointer back to 'button',
|
|
|
|
* since there's no property for that we can't do it in the template
|
|
|
|
*/
|
|
|
|
GTK_SCALE_BUTTON_SCALE (priv->scale)->button = button;
|
|
|
|
|
|
|
|
/* Need a local reference to the adjustment */
|
|
|
|
g_object_ref (priv->adjustment);
|
2012-02-23 13:47:13 +00:00
|
|
|
|
|
|
|
gtk_widget_add_events (GTK_WIDGET (button), GDK_SCROLL_MASK);
|
2008-06-27 09:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
gtk_scale_button_constructor (GType type,
|
|
|
|
guint n_construct_properties,
|
|
|
|
GObjectConstructParam *construct_params)
|
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
GtkScaleButton *button;
|
|
|
|
GtkScaleButtonPrivate *priv;
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (gtk_scale_button_parent_class)->constructor (type, n_construct_properties, construct_params);
|
|
|
|
|
|
|
|
button = GTK_SCALE_BUTTON (object);
|
|
|
|
|
|
|
|
priv = button->priv;
|
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
/* set button text and size */
|
|
|
|
priv->size = GTK_ICON_SIZE_SMALL_TOOLBAR;
|
|
|
|
gtk_scale_button_update_icon (button);
|
2008-06-27 09:33:32 +00:00
|
|
|
|
|
|
|
return object;
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_scale_button_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2008-06-30 23:41:10 +00:00
|
|
|
GtkScaleButton *button = GTK_SCALE_BUTTON (object);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2008-06-27 09:33:32 +00:00
|
|
|
case PROP_ORIENTATION:
|
2009-03-18 21:19:07 +00:00
|
|
|
gtk_scale_button_set_orientation_private (button, g_value_get_enum (value));
|
2008-06-27 09:33:32 +00:00
|
|
|
break;
|
2007-05-19 23:08:02 +00:00
|
|
|
case PROP_VALUE:
|
|
|
|
gtk_scale_button_set_value (button, g_value_get_double (value));
|
|
|
|
break;
|
|
|
|
case PROP_SIZE:
|
|
|
|
{
|
|
|
|
GtkIconSize size;
|
|
|
|
size = g_value_get_enum (value);
|
|
|
|
if (button->priv->size != size)
|
|
|
|
{
|
|
|
|
button->priv->size = size;
|
|
|
|
gtk_scale_button_update_icon (button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_ADJUSTMENT:
|
|
|
|
gtk_scale_button_set_adjustment (button, g_value_get_object (value));
|
|
|
|
break;
|
2007-06-10 01:26:28 +00:00
|
|
|
case PROP_ICONS:
|
2008-06-26 17:14:27 +00:00
|
|
|
gtk_scale_button_set_icons (button,
|
2007-06-10 01:26:28 +00:00
|
|
|
(const gchar **)g_value_get_boxed (value));
|
|
|
|
break;
|
2007-05-19 23:08:02 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-26 17:14:27 +00:00
|
|
|
static void
|
2007-05-19 23:08:02 +00:00
|
|
|
gtk_scale_button_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2008-06-30 23:41:10 +00:00
|
|
|
GtkScaleButton *button = GTK_SCALE_BUTTON (object);
|
|
|
|
GtkScaleButtonPrivate *priv = button->priv;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2008-06-27 09:33:32 +00:00
|
|
|
case PROP_ORIENTATION:
|
|
|
|
g_value_set_enum (value, priv->orientation);
|
|
|
|
break;
|
2007-05-19 23:08:02 +00:00
|
|
|
case PROP_VALUE:
|
2007-09-13 21:25:48 +00:00
|
|
|
g_value_set_double (value, gtk_scale_button_get_value (button));
|
2007-05-19 23:08:02 +00:00
|
|
|
break;
|
|
|
|
case PROP_SIZE:
|
|
|
|
g_value_set_enum (value, priv->size);
|
|
|
|
break;
|
|
|
|
case PROP_ADJUSTMENT:
|
|
|
|
g_value_set_object (value, gtk_scale_button_get_adjustment (button));
|
|
|
|
break;
|
2007-06-10 01:26:28 +00:00
|
|
|
case PROP_ICONS:
|
|
|
|
g_value_set_boxed (value, priv->icon_list);
|
|
|
|
break;
|
2007-05-19 23:08:02 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-06-10 15:32:02 +00:00
|
|
|
gtk_scale_button_finalize (GObject *object)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
2007-06-10 15:32:02 +00:00
|
|
|
GtkScaleButton *button = GTK_SCALE_BUTTON (object);
|
|
|
|
GtkScaleButtonPrivate *priv = button->priv;
|
2008-06-26 17:14:27 +00:00
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
if (priv->icon_list)
|
|
|
|
{
|
|
|
|
g_strfreev (priv->icon_list);
|
|
|
|
priv->icon_list = NULL;
|
|
|
|
}
|
2008-06-26 17:14:27 +00:00
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
if (priv->adjustment)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->adjustment);
|
|
|
|
priv->adjustment = NULL;
|
|
|
|
}
|
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
G_OBJECT_CLASS (gtk_scale_button_parent_class)->finalize (object);
|
|
|
|
}
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
static void
|
|
|
|
gtk_scale_button_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button = GTK_SCALE_BUTTON (object);
|
|
|
|
GtkScaleButtonPrivate *priv = button->priv;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
if (priv->dock)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
gtk_widget_destroy (priv->dock);
|
|
|
|
priv->dock = NULL;
|
|
|
|
}
|
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
if (priv->click_id != 0)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
g_source_remove (priv->click_id);
|
|
|
|
priv->click_id = 0;
|
|
|
|
}
|
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
G_OBJECT_CLASS (gtk_scale_button_parent_class)->dispose (object);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-20 14:22:26 +00:00
|
|
|
* gtk_scale_button_new:
|
2010-09-23 20:56:48 +00:00
|
|
|
* @size: (type int): a stock icon size
|
2007-05-26 20:22:51 +00:00
|
|
|
* @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)
|
2011-01-18 09:10:30 +00:00
|
|
|
* @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()
|
2007-05-19 23:08:02 +00:00
|
|
|
*
|
2007-05-26 20:22:51 +00:00
|
|
|
* Creates a #GtkScaleButton, with a range between @min and @max, with
|
|
|
|
* a stepping of @step.
|
2007-05-19 23:08:02 +00:00
|
|
|
*
|
|
|
|
* Return value: a new #GtkScaleButton
|
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_scale_button_new (GtkIconSize size,
|
2007-05-26 20:22:51 +00:00
|
|
|
gdouble min,
|
|
|
|
gdouble max,
|
|
|
|
gdouble step,
|
2007-05-19 23:08:02 +00:00
|
|
|
const gchar **icons)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button;
|
2011-01-05 22:02:10 +00:00
|
|
|
GtkAdjustment *adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2011-01-05 22:02:10 +00:00
|
|
|
adjustment = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
|
2008-06-26 17:14:27 +00:00
|
|
|
|
|
|
|
button = g_object_new (GTK_TYPE_SCALE_BUTTON,
|
2011-01-05 22:02:10 +00:00
|
|
|
"adjustment", adjustment,
|
2007-06-10 01:26:28 +00:00
|
|
|
"icons", icons,
|
|
|
|
"size", size,
|
|
|
|
NULL);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
return GTK_WIDGET (button);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-20 14:22:26 +00:00
|
|
|
* gtk_scale_button_get_value:
|
2007-05-19 23:08:02 +00:00
|
|
|
* @button: a #GtkScaleButton
|
|
|
|
*
|
|
|
|
* Gets the current value of the scale button.
|
|
|
|
*
|
|
|
|
* Return value: current value of the scale button
|
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
*/
|
|
|
|
gdouble
|
|
|
|
gtk_scale_button_get_value (GtkScaleButton * button)
|
|
|
|
{
|
|
|
|
GtkScaleButtonPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_SCALE_BUTTON (button), 0);
|
|
|
|
|
|
|
|
priv = button->priv;
|
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
return gtk_adjustment_get_value (priv->adjustment);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-20 14:22:26 +00:00
|
|
|
* gtk_scale_button_set_value:
|
2007-05-19 23:08:02 +00:00
|
|
|
* @button: a #GtkScaleButton
|
|
|
|
* @value: new value of the scale button
|
|
|
|
*
|
2008-06-26 17:14:27 +00:00
|
|
|
* Sets the current value of the scale; if the value is outside
|
|
|
|
* the minimum or maximum range values, it will be clamped to fit
|
|
|
|
* inside them. The scale button emits the #GtkScaleButton::value-changed
|
2007-06-10 01:26:28 +00:00
|
|
|
* signal if the value changes.
|
2007-05-19 23:08:02 +00:00
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_scale_button_set_value (GtkScaleButton *button,
|
|
|
|
gdouble value)
|
|
|
|
{
|
|
|
|
GtkScaleButtonPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SCALE_BUTTON (button));
|
|
|
|
|
|
|
|
priv = button->priv;
|
|
|
|
|
|
|
|
gtk_range_set_value (GTK_RANGE (priv->scale), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-20 14:22:26 +00:00
|
|
|
* gtk_scale_button_set_icons:
|
2007-05-19 23:08:02 +00:00
|
|
|
* @button: a #GtkScaleButton
|
2011-01-18 09:10:30 +00:00
|
|
|
* @icons: (array zero-terminated=1): a %NULL-terminated array of icon names
|
2007-05-19 23:08:02 +00:00
|
|
|
*
|
2008-06-26 17:14:27 +00:00
|
|
|
* Sets the icons to be used by the scale button.
|
2007-06-10 01:26:28 +00:00
|
|
|
* For details, see the #GtkScaleButton:icons property.
|
2007-05-19 23:08:02 +00:00
|
|
|
*
|
2007-07-23 18:33:35 +00:00
|
|
|
* Since: 2.12
|
2007-05-19 23:08:02 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_scale_button_set_icons (GtkScaleButton *button,
|
|
|
|
const gchar **icons)
|
|
|
|
{
|
|
|
|
GtkScaleButtonPrivate *priv;
|
2007-06-10 01:26:28 +00:00
|
|
|
gchar **tmp;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SCALE_BUTTON (button));
|
|
|
|
|
|
|
|
priv = button->priv;
|
|
|
|
|
2007-06-10 01:26:28 +00:00
|
|
|
tmp = priv->icon_list;
|
2007-05-19 23:08:02 +00:00
|
|
|
priv->icon_list = g_strdupv ((gchar **) icons);
|
2007-06-10 01:26:28 +00:00
|
|
|
g_strfreev (tmp);
|
2007-05-19 23:08:02 +00:00
|
|
|
gtk_scale_button_update_icon (button);
|
2007-06-10 01:26:28 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (button), "icons");
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-06-10 01:26:28 +00:00
|
|
|
* gtk_scale_button_get_adjustment:
|
2007-05-19 23:08:02 +00:00
|
|
|
* @button: a #GtkScaleButton
|
|
|
|
*
|
|
|
|
* Gets the #GtkAdjustment associated with the #GtkScaleButton's scale.
|
|
|
|
* See gtk_range_get_adjustment() for details.
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
* Returns: (transfer none): the adjustment associated with the scale
|
2007-05-26 20:22:51 +00:00
|
|
|
*
|
2007-05-19 23:08:02 +00:00
|
|
|
* Since: 2.12
|
|
|
|
*/
|
|
|
|
GtkAdjustment*
|
|
|
|
gtk_scale_button_get_adjustment (GtkScaleButton *button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_SCALE_BUTTON (button), NULL);
|
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
return button->priv->adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-20 14:22:26 +00:00
|
|
|
* gtk_scale_button_set_adjustment:
|
2007-05-19 23:08:02 +00:00
|
|
|
* @button: a #GtkScaleButton
|
|
|
|
* @adjustment: a #GtkAdjustment
|
|
|
|
*
|
2008-06-26 17:14:27 +00:00
|
|
|
* Sets the #GtkAdjustment to be used as a model
|
2007-06-10 01:26:28 +00:00
|
|
|
* for the #GtkScaleButton's scale.
|
2007-05-19 23:08:02 +00:00
|
|
|
* See gtk_range_set_adjustment() for details.
|
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_scale_button_set_adjustment (GtkScaleButton *button,
|
|
|
|
GtkAdjustment *adjustment)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_SCALE_BUTTON (button));
|
2010-09-27 13:10:12 +00:00
|
|
|
|
2008-10-09 16:19:06 +00:00
|
|
|
if (!adjustment)
|
2010-09-27 13:10:12 +00:00
|
|
|
adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
|
2008-10-09 16:19:06 +00:00
|
|
|
else
|
|
|
|
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2008-10-09 16:19:06 +00:00
|
|
|
if (button->priv->adjustment != adjustment)
|
|
|
|
{
|
|
|
|
if (button->priv->adjustment)
|
|
|
|
g_object_unref (button->priv->adjustment);
|
|
|
|
button->priv->adjustment = g_object_ref_sink (adjustment);
|
2008-06-27 09:33:32 +00:00
|
|
|
|
2008-10-09 16:19:06 +00:00
|
|
|
if (button->priv->scale)
|
|
|
|
gtk_range_set_adjustment (GTK_RANGE (button->priv->scale), adjustment);
|
2007-06-10 01:26:28 +00:00
|
|
|
|
2008-10-09 16:19:06 +00:00
|
|
|
g_object_notify (G_OBJECT (button), "adjustment");
|
|
|
|
}
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
2008-07-04 09:02:20 +00:00
|
|
|
/**
|
|
|
|
* gtk_scale_button_get_plus_button:
|
|
|
|
* @button: a #GtkScaleButton
|
|
|
|
*
|
|
|
|
* Retrieves the plus button of the #GtkScaleButton.
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
* Returns: (transfer none): the plus button of the #GtkScaleButton
|
2008-07-21 23:23:41 +00:00
|
|
|
*
|
2008-07-04 09:02:20 +00:00
|
|
|
* Since: 2.14
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_scale_button_get_plus_button (GtkScaleButton *button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_SCALE_BUTTON (button), NULL);
|
|
|
|
|
2010-07-08 01:13:10 +00:00
|
|
|
return button->priv->plus_button;
|
2008-07-04 09:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_scale_button_get_minus_button:
|
|
|
|
* @button: a #GtkScaleButton
|
|
|
|
*
|
|
|
|
* Retrieves the minus button of the #GtkScaleButton.
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
* Returns: (transfer none): the minus button of the #GtkScaleButton
|
2008-07-21 23:23:41 +00:00
|
|
|
*
|
2008-07-04 09:02:20 +00:00
|
|
|
* Since: 2.14
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_scale_button_get_minus_button (GtkScaleButton *button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_SCALE_BUTTON (button), NULL);
|
|
|
|
|
2010-07-08 01:13:10 +00:00
|
|
|
return button->priv->minus_button;
|
2008-07-04 09:02:20 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 18:03:13 +00:00
|
|
|
/**
|
|
|
|
* gtk_scale_button_get_popup:
|
|
|
|
* @button: a #GtkScaleButton
|
|
|
|
*
|
|
|
|
* Retrieves the popup of the #GtkScaleButton.
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
* Returns: (transfer none): the popup of the #GtkScaleButton
|
2008-07-04 22:03:37 +00:00
|
|
|
*
|
2008-07-03 18:03:13 +00:00
|
|
|
* Since: 2.14
|
|
|
|
*/
|
2008-07-04 09:02:20 +00:00
|
|
|
GtkWidget *
|
2008-07-03 18:03:13 +00:00
|
|
|
gtk_scale_button_get_popup (GtkScaleButton *button)
|
|
|
|
{
|
2008-07-04 05:05:45 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_SCALE_BUTTON (button), NULL);
|
2008-07-03 18:03:13 +00:00
|
|
|
|
|
|
|
return button->priv->dock;
|
|
|
|
}
|
|
|
|
|
2009-03-18 21:19:07 +00:00
|
|
|
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),
|
2010-07-08 01:13:10 +00:00
|
|
|
priv->plus_button,
|
2009-03-18 21:19:07 +00:00
|
|
|
"pack-type",
|
|
|
|
orientation == GTK_ORIENTATION_VERTICAL ?
|
|
|
|
GTK_PACK_START : GTK_PACK_END,
|
|
|
|
NULL);
|
|
|
|
gtk_container_child_set (GTK_CONTAINER (priv->box),
|
2010-07-08 01:13:10 +00:00
|
|
|
priv->minus_button,
|
2009-03-18 21:19:07 +00:00
|
|
|
"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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
/*
|
|
|
|
* button callbacks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_scale_button_scroll (GtkWidget *widget,
|
|
|
|
GdkEventScroll *event)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button;
|
|
|
|
GtkScaleButtonPrivate *priv;
|
2011-01-05 22:02:10 +00:00
|
|
|
GtkAdjustment *adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
gdouble d;
|
|
|
|
|
|
|
|
button = GTK_SCALE_BUTTON (widget);
|
|
|
|
priv = button->priv;
|
2011-01-05 22:02:10 +00:00
|
|
|
adjustment = priv->adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
if (event->type != GDK_SCROLL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
d = gtk_scale_button_get_value (button);
|
|
|
|
if (event->direction == GDK_SCROLL_UP)
|
|
|
|
{
|
2011-01-05 22:02:10 +00:00
|
|
|
d += gtk_adjustment_get_step_increment (adjustment);
|
|
|
|
if (d > gtk_adjustment_get_upper (adjustment))
|
|
|
|
d = gtk_adjustment_get_upper (adjustment);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-05 22:02:10 +00:00
|
|
|
d -= gtk_adjustment_get_step_increment (adjustment);
|
|
|
|
if (d < gtk_adjustment_get_lower (adjustment))
|
|
|
|
d = gtk_adjustment_get_lower (adjustment);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
gtk_scale_button_set_value (button, d);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_scale_button_screen_changed (GtkWidget *widget,
|
|
|
|
GdkScreen *previous_screen)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button = (GtkScaleButton *) widget;
|
|
|
|
GtkScaleButtonPrivate *priv;
|
|
|
|
GdkScreen *screen;
|
2011-09-30 15:31:04 +00:00
|
|
|
GValue value = G_VALUE_INIT;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
if (gtk_widget_has_screen (widget) == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv = button->priv;
|
|
|
|
|
|
|
|
screen = gtk_widget_get_screen (widget);
|
|
|
|
g_value_init (&value, G_TYPE_INT);
|
|
|
|
if (gdk_screen_get_setting (screen,
|
|
|
|
"gtk-double-click-time",
|
|
|
|
&value) == FALSE)
|
|
|
|
{
|
|
|
|
priv->click_timeout = CLICK_TIMEOUT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->click_timeout = g_value_get_int (&value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_scale_popup (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
guint32 time)
|
|
|
|
{
|
2010-08-11 21:02:16 +00:00
|
|
|
GtkAllocation allocation, dock_allocation, scale_allocation;
|
2007-05-19 23:08:02 +00:00
|
|
|
GtkScaleButton *button;
|
|
|
|
GtkScaleButtonPrivate *priv;
|
2011-01-05 22:02:10 +00:00
|
|
|
GtkAdjustment *adjustment;
|
2008-06-27 09:33:32 +00:00
|
|
|
gint x, y, m, dx, dy, sx, sy, startoff;
|
2010-08-12 23:43:27 +00:00
|
|
|
gint min_slider_size;
|
2007-05-19 23:08:02 +00:00
|
|
|
gdouble v;
|
|
|
|
GdkScreen *screen;
|
2009-06-22 16:19:21 +00:00
|
|
|
gboolean is_moved;
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDevice *device, *keyboard, *pointer;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2009-06-22 16:19:21 +00:00
|
|
|
is_moved = FALSE;
|
2007-05-19 23:08:02 +00:00
|
|
|
button = GTK_SCALE_BUTTON (widget);
|
|
|
|
priv = button->priv;
|
2011-01-05 22:02:10 +00:00
|
|
|
adjustment = priv->adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
screen = gtk_widget_get_screen (widget);
|
2010-08-11 21:02:16 +00:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
/* position roughly */
|
|
|
|
gtk_window_set_screen (GTK_WINDOW (priv->dock), screen);
|
|
|
|
|
2010-08-11 21:02:16 +00:00
|
|
|
gdk_window_get_origin (gtk_widget_get_window (widget),
|
|
|
|
&x, &y);
|
|
|
|
x += allocation.x;
|
|
|
|
y += allocation.y;
|
2008-06-27 09:33:32 +00:00
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
|
|
|
|
gtk_window_move (GTK_WINDOW (priv->dock), x, y - (SCALE_SIZE / 2));
|
|
|
|
else
|
|
|
|
gtk_window_move (GTK_WINDOW (priv->dock), x - (SCALE_SIZE / 2), y);
|
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
gtk_widget_show_all (priv->dock);
|
2008-06-27 09:33:32 +00:00
|
|
|
|
2010-08-11 21:02:16 +00:00
|
|
|
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;
|
2008-06-27 09:33:32 +00:00
|
|
|
|
2010-08-11 21:02:16 +00:00
|
|
|
|
|
|
|
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;
|
2008-06-27 09:33:32 +00:00
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
priv->timeout = TRUE;
|
|
|
|
|
|
|
|
/* position (needs widget to be shown already) */
|
2011-01-05 22:02:10 +00:00
|
|
|
v = gtk_scale_button_get_value (button) / (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment));
|
2010-08-12 23:43:27 +00:00
|
|
|
min_slider_size = gtk_range_get_min_slider_size (GTK_RANGE (priv->scale));
|
2008-06-27 09:33:32 +00:00
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
|
|
|
|
{
|
|
|
|
startoff = sy - dy;
|
|
|
|
|
2010-08-11 21:02:16 +00:00
|
|
|
x += (allocation.width - dock_allocation.width) / 2;
|
2008-06-27 09:33:32 +00:00
|
|
|
y -= startoff;
|
2010-08-12 23:43:27 +00:00
|
|
|
y -= min_slider_size / 2;
|
|
|
|
m = scale_allocation.height - min_slider_size;
|
2008-06-27 09:33:32 +00:00
|
|
|
y -= m * (1.0 - v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
startoff = sx - dx;
|
|
|
|
|
|
|
|
x -= startoff;
|
2010-08-11 21:02:16 +00:00
|
|
|
y += (allocation.height - dock_allocation.height) / 2;
|
2010-08-12 23:43:27 +00:00
|
|
|
x -= min_slider_size / 2;
|
|
|
|
m = scale_allocation.width - min_slider_size;
|
2008-06-27 09:33:32 +00:00
|
|
|
x -= m * v;
|
|
|
|
}
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
/* Make sure the dock stays inside the monitor */
|
|
|
|
if (event->type == GDK_BUTTON_PRESS)
|
|
|
|
{
|
2010-08-11 21:02:16 +00:00
|
|
|
GtkAllocation d_allocation;
|
2007-05-19 23:08:02 +00:00
|
|
|
int monitor;
|
|
|
|
GdkEventButton *button_event = (GdkEventButton *) event;
|
|
|
|
GdkRectangle rect;
|
|
|
|
GtkWidget *d;
|
|
|
|
|
|
|
|
d = GTK_WIDGET (priv->dock);
|
|
|
|
monitor = gdk_screen_get_monitor_at_point (screen,
|
2007-05-21 02:58:16 +00:00
|
|
|
button_event->x_root,
|
|
|
|
button_event->y_root);
|
2011-12-18 19:28:01 +00:00
|
|
|
gdk_screen_get_monitor_workarea (screen, monitor, &rect);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
|
|
|
|
y += button_event->y;
|
|
|
|
else
|
|
|
|
x += button_event->x;
|
|
|
|
|
2009-06-22 16:19:21 +00:00
|
|
|
/* 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 */
|
2010-08-11 21:02:16 +00:00
|
|
|
gtk_widget_get_allocation (d, &d_allocation);
|
2010-05-25 22:38:44 +00:00
|
|
|
if (y < rect.y)
|
|
|
|
{
|
|
|
|
y = rect.y;
|
|
|
|
is_moved = TRUE;
|
|
|
|
}
|
2010-08-11 21:02:16 +00:00
|
|
|
else if (y + d_allocation.height > rect.height + rect.y)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-08-11 21:02:16 +00:00
|
|
|
y = rect.y + rect.height - d_allocation.height;
|
2010-05-25 22:38:44 +00:00
|
|
|
is_moved = TRUE;
|
|
|
|
}
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
if (x < rect.x)
|
|
|
|
{
|
|
|
|
x = rect.x;
|
|
|
|
is_moved = TRUE;
|
|
|
|
}
|
2010-08-11 21:02:16 +00:00
|
|
|
else if (x + d_allocation.width > rect.width + rect.x)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-08-11 21:02:16 +00:00
|
|
|
x = rect.x + rect.width - d_allocation.width;
|
2010-05-25 22:38:44 +00:00
|
|
|
is_moved = TRUE;
|
|
|
|
}
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_window_move (GTK_WINDOW (priv->dock), x, y);
|
|
|
|
|
|
|
|
if (event->type == GDK_BUTTON_PRESS)
|
2007-06-10 15:32:02 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_scale_button_parent_class)->button_press_event (widget, (GdkEventButton *) event);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
device = gdk_event_get_device (event);
|
|
|
|
|
2010-11-23 19:25:13 +00:00
|
|
|
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
keyboard = device;
|
|
|
|
pointer = gdk_device_get_associated_device (device);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pointer = device;
|
|
|
|
keyboard = gdk_device_get_associated_device (device);
|
|
|
|
}
|
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
/* grab focus */
|
2010-05-25 22:38:44 +00:00
|
|
|
gtk_device_grab_add (priv->dock, pointer, TRUE);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2010-08-11 21:02:16 +00:00
|
|
|
if (gdk_device_grab (pointer, gtk_widget_get_window (priv->dock),
|
2010-05-25 22:38:44 +00:00
|
|
|
GDK_OWNERSHIP_WINDOW, TRUE,
|
|
|
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK, NULL, time) != GDK_GRAB_SUCCESS)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
2010-05-25 22:38:44 +00:00
|
|
|
gtk_device_grab_remove (priv->dock, pointer);
|
2007-05-19 23:08:02 +00:00
|
|
|
gtk_widget_hide (priv->dock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-08-11 21:02:16 +00:00
|
|
|
if (gdk_device_grab (keyboard, gtk_widget_get_window (priv->dock),
|
2010-05-25 22:38:44 +00:00
|
|
|
GDK_OWNERSHIP_WINDOW, TRUE,
|
|
|
|
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
|
|
|
|
NULL, time) != GDK_GRAB_SUCCESS)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
2010-05-25 22:38:44 +00:00
|
|
|
gdk_device_ungrab (pointer, time);
|
|
|
|
gtk_device_grab_remove (priv->dock, pointer);
|
2007-05-19 23:08:02 +00:00
|
|
|
gtk_widget_hide (priv->dock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (priv->dock);
|
2010-05-25 22:38:44 +00:00
|
|
|
priv->grab_keyboard = keyboard;
|
|
|
|
priv->grab_pointer = pointer;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2009-06-22 16:19:21 +00:00
|
|
|
if (event->type == GDK_BUTTON_PRESS && !is_moved)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
GdkEventButton *e;
|
|
|
|
GdkEventButton *button_event = (GdkEventButton *) event;
|
|
|
|
|
|
|
|
/* forward event to the slider */
|
|
|
|
e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event);
|
2010-08-11 21:02:16 +00:00
|
|
|
e->window = gtk_widget_get_window (priv->scale);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
/* 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
|
2008-06-27 09:33:32 +00:00
|
|
|
* position, which means a position change on-click, which is bad.
|
|
|
|
*/
|
2010-08-11 21:02:16 +00:00
|
|
|
gtk_widget_get_allocation (priv->scale, &scale_allocation);
|
2008-06-27 09:33:32 +00:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
|
|
|
|
{
|
2010-08-11 21:02:16 +00:00
|
|
|
e->x = scale_allocation.width / 2;
|
2010-08-12 23:43:27 +00:00
|
|
|
m = scale_allocation.height - min_slider_size;
|
|
|
|
e->y = ((1.0 - v) * m) + min_slider_size / 2;
|
2008-06-27 09:33:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-11 21:02:16 +00:00
|
|
|
e->y = scale_allocation.height / 2;
|
2010-08-12 23:43:27 +00:00
|
|
|
m = scale_allocation.width - min_slider_size;
|
|
|
|
e->x = (v * m) + min_slider_size / 2;
|
2008-06-27 09:33:32 +00:00
|
|
|
}
|
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
gtk_widget_event (priv->scale, (GdkEvent *) e);
|
|
|
|
e->window = button_event->window;
|
|
|
|
gdk_event_free ((GdkEvent *) e);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (priv->scale);
|
|
|
|
|
|
|
|
priv->pop_time = time;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_scale_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
|
|
|
return gtk_scale_popup (widget, (GdkEvent *) event, event->time);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-07-03 13:13:23 +00:00
|
|
|
gtk_scale_button_popup (GtkWidget *widget)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
GdkEvent *ev;
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
/* 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);
|
2007-05-19 23:08:02 +00:00
|
|
|
gdk_event_free (ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_scale_button_key_release (GtkWidget *widget,
|
|
|
|
GdkEventKey *event)
|
|
|
|
{
|
2010-09-18 23:57:32 +00:00
|
|
|
return gtk_bindings_activate_event (G_OBJECT (widget), event);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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,
|
2011-01-24 02:50:39 +00:00
|
|
|
gboolean was_grabbed)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
GtkScaleButtonPrivate *priv;
|
2010-05-25 22:38:44 +00:00
|
|
|
GtkWidget *toplevel, *grab_widget;
|
|
|
|
GtkWindowGroup *group;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
priv = button->priv;
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
if (!priv->grab_pointer ||
|
|
|
|
!gtk_widget_device_is_shadowed (GTK_WIDGET (button), priv->grab_pointer))
|
2007-10-04 12:52:46 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
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))
|
2007-05-19 23:08:02 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
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;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
/* hide again */
|
|
|
|
gtk_widget_hide (priv->dock);
|
|
|
|
priv->timeout = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* +/- button callbacks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
cb_button_timeout (gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button;
|
|
|
|
GtkScaleButtonPrivate *priv;
|
2011-01-05 22:02:10 +00:00
|
|
|
GtkAdjustment *adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
gdouble val;
|
|
|
|
gboolean res = TRUE;
|
|
|
|
|
|
|
|
button = GTK_SCALE_BUTTON (user_data);
|
|
|
|
priv = button->priv;
|
|
|
|
|
|
|
|
if (priv->click_id == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-01-05 22:02:10 +00:00
|
|
|
adjustment = priv->adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
val = gtk_scale_button_get_value (button);
|
|
|
|
val += priv->direction;
|
2011-01-05 22:02:10 +00:00
|
|
|
if (val <= gtk_adjustment_get_lower (adjustment))
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
res = FALSE;
|
2011-01-05 22:02:10 +00:00
|
|
|
val = gtk_adjustment_get_lower (adjustment);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
2011-01-05 22:02:10 +00:00
|
|
|
else if (val > gtk_adjustment_get_upper (adjustment))
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
res = FALSE;
|
2011-01-05 22:02:10 +00:00
|
|
|
val = gtk_adjustment_get_upper (adjustment);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
gtk_scale_button_set_value (button, val);
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
g_source_remove (priv->click_id);
|
|
|
|
priv->click_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
cb_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button;
|
|
|
|
GtkScaleButtonPrivate *priv;
|
2011-01-05 22:02:10 +00:00
|
|
|
GtkAdjustment *adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
button = GTK_SCALE_BUTTON (user_data);
|
|
|
|
priv = button->priv;
|
2011-01-05 22:02:10 +00:00
|
|
|
adjustment = priv->adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
if (priv->click_id != 0)
|
|
|
|
g_source_remove (priv->click_id);
|
|
|
|
|
2010-07-08 01:13:10 +00:00
|
|
|
if (widget == priv->plus_button)
|
2011-01-05 22:02:10 +00:00
|
|
|
priv->direction = fabs (gtk_adjustment_get_page_increment (adjustment));
|
2007-05-19 23:08:02 +00:00
|
|
|
else
|
2011-01-05 22:02:10 +00:00
|
|
|
priv->direction = - fabs (gtk_adjustment_get_page_increment (adjustment));
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
priv->click_id = gdk_threads_add_timeout (priv->click_timeout,
|
|
|
|
cb_button_timeout,
|
|
|
|
button);
|
2007-05-19 23:08:02 +00:00
|
|
|
cb_button_timeout (button);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
cb_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button;
|
|
|
|
GtkScaleButtonPrivate *priv;
|
|
|
|
|
|
|
|
button = GTK_SCALE_BUTTON (user_data);
|
|
|
|
priv = button->priv;
|
|
|
|
|
|
|
|
if (priv->click_id != 0)
|
|
|
|
{
|
|
|
|
g_source_remove (priv->click_id);
|
|
|
|
priv->click_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cb_dock_grab_notify (GtkWidget *widget,
|
|
|
|
gboolean was_grabbed,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button = (GtkScaleButton *) user_data;
|
|
|
|
|
|
|
|
gtk_scale_button_grab_notify (button, was_grabbed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
cb_dock_grab_broken_event (GtkWidget *widget,
|
2010-05-25 22:38:44 +00:00
|
|
|
gboolean was_grabbed,
|
2007-05-19 23:08:02 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button = (GtkScaleButton *) user_data;
|
|
|
|
|
|
|
|
gtk_scale_button_grab_notify (button, FALSE);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
/* Scale callbacks */
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_scale_button_release_grab (GtkScaleButton *button,
|
2011-01-24 02:50:39 +00:00
|
|
|
GdkEventButton *event)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
GdkEventButton *e;
|
|
|
|
GtkScaleButtonPrivate *priv;
|
|
|
|
|
|
|
|
priv = button->priv;
|
|
|
|
|
|
|
|
/* ungrab focus */
|
2010-05-25 22:38:44 +00:00
|
|
|
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;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
/* hide again */
|
|
|
|
gtk_widget_hide (priv->dock);
|
|
|
|
priv->timeout = FALSE;
|
|
|
|
|
|
|
|
e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event);
|
2010-08-11 21:02:16 +00:00
|
|
|
e->window = gtk_widget_get_window (GTK_WIDGET (button));
|
2007-05-19 23:08:02 +00:00
|
|
|
e->type = GDK_BUTTON_RELEASE;
|
|
|
|
gtk_widget_event (GTK_WIDGET (button), (GdkEvent *) e);
|
|
|
|
e->window = event->window;
|
|
|
|
gdk_event_free ((GdkEvent *) e);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
cb_dock_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button = GTK_SCALE_BUTTON (user_data);
|
|
|
|
|
|
|
|
if (event->type == GDK_BUTTON_PRESS)
|
|
|
|
{
|
|
|
|
gtk_scale_button_release_grab (button, event);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-07-03 13:13:23 +00:00
|
|
|
gtk_scale_button_popdown (GtkWidget *widget)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
GtkScaleButton *button;
|
|
|
|
GtkScaleButtonPrivate *priv;
|
|
|
|
|
|
|
|
button = GTK_SCALE_BUTTON (widget);
|
|
|
|
priv = button->priv;
|
|
|
|
|
|
|
|
/* ungrab focus */
|
2010-05-25 22:38:44 +00:00
|
|
|
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;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
/* hide again */
|
|
|
|
gtk_widget_hide (priv->dock);
|
|
|
|
priv->timeout = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
cb_dock_key_release (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2010-09-08 17:35:51 +00:00
|
|
|
if (event->keyval == GDK_KEY_Escape)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
2008-07-03 13:13:23 +00:00
|
|
|
gtk_scale_button_popdown (GTK_WIDGET (user_data));
|
2007-05-19 23:08:02 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-18 23:57:32 +00:00
|
|
|
if (!gtk_bindings_activate_event (G_OBJECT (widget), event))
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
/* The popup hasn't managed the event, pass onto the button */
|
2010-09-18 23:57:32 +00:00
|
|
|
gtk_bindings_activate_event (G_OBJECT (user_data), event);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cb_scale_grab_notify (GtkWidget *widget,
|
|
|
|
gboolean was_grabbed,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkScaleButton *button = (GtkScaleButton *) user_data;
|
|
|
|
|
|
|
|
gtk_scale_button_grab_notify (button, was_grabbed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scale stuff.
|
|
|
|
*/
|
2009-02-19 15:10:34 +00:00
|
|
|
typedef struct _GtkScaleButtonScaleClass
|
|
|
|
{
|
|
|
|
GtkScaleClass parent_class;
|
|
|
|
} GtkScaleButtonScaleClass;
|
2008-06-27 09:33:32 +00:00
|
|
|
|
|
|
|
static gboolean gtk_scale_button_scale_press (GtkWidget *widget,
|
2008-06-26 17:14:27 +00:00
|
|
|
GdkEventButton *event);
|
|
|
|
static gboolean gtk_scale_button_scale_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2009-02-19 15:10:34 +00:00
|
|
|
G_DEFINE_TYPE (GtkScaleButtonScale, _gtk_scale_button_scale, GTK_TYPE_SCALE)
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
static void
|
2009-02-19 15:10:34 +00:00
|
|
|
_gtk_scale_button_scale_class_init (GtkScaleButtonScaleClass *klass)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
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
|
2009-02-19 15:10:34 +00:00
|
|
|
_gtk_scale_button_scale_init (GtkScaleButtonScale *scale)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_scale_button_scale_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
2013-03-23 11:17:15 +00:00
|
|
|
GtkScaleButtonPrivate *priv;
|
|
|
|
|
|
|
|
/* Avoid a crash when using a GtkScaleButtonScale without a GtkScaleButton,
|
|
|
|
* this can happen while editing gtkscalebutton.ui in Glade
|
|
|
|
*/
|
|
|
|
if (!GTK_SCALE_BUTTON_SCALE (widget)->button)
|
|
|
|
return GTK_WIDGET_CLASS (_gtk_scale_button_scale_parent_class)->button_release_event (widget, event);
|
|
|
|
|
|
|
|
priv = GTK_SCALE_BUTTON_SCALE (widget)->button->priv;
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
/* the scale will grab input; if we have input grabbed, all goes
|
2009-02-19 15:10:34 +00:00
|
|
|
* horribly wrong, so let's not do that.
|
|
|
|
*/
|
2010-05-25 22:38:44 +00:00
|
|
|
gtk_device_grab_remove (priv->dock, event->device);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
2009-02-19 15:10:34 +00:00
|
|
|
return GTK_WIDGET_CLASS (_gtk_scale_button_scale_parent_class)->button_press_event (widget, event);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_scale_button_scale_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
2009-02-19 15:10:34 +00:00
|
|
|
GtkScaleButton *button = GTK_SCALE_BUTTON_SCALE (widget)->button;
|
2007-05-19 23:08:02 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2013-03-23 11:17:15 +00:00
|
|
|
/* Avoid a crash when using a GtkScaleButtonScale without a GtkScaleButton,
|
|
|
|
* this can happen while editing gtkscalebutton.ui in Glade
|
|
|
|
*/
|
|
|
|
if (!button)
|
|
|
|
return GTK_WIDGET_CLASS (_gtk_scale_button_scale_parent_class)->button_release_event (widget, event);
|
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
if (button->priv->timeout)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
/* if we did a quick click, leave the window open; else, hide it */
|
2008-06-27 09:33:32 +00:00
|
|
|
if (event->time > button->priv->pop_time + button->priv->click_timeout)
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
2007-06-10 15:32:02 +00:00
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
gtk_scale_button_release_grab (button, event);
|
2009-02-19 15:10:34 +00:00
|
|
|
GTK_WIDGET_CLASS (_gtk_scale_button_scale_parent_class)->button_release_event (widget, event);
|
2007-06-10 15:32:02 +00:00
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2007-06-10 15:32:02 +00:00
|
|
|
|
2008-06-27 09:33:32 +00:00
|
|
|
button->priv->timeout = FALSE;
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
2009-02-19 15:10:34 +00:00
|
|
|
res = GTK_WIDGET_CLASS (_gtk_scale_button_scale_parent_class)->button_release_event (widget, event);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
/* 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,
|
|
|
|
* so I basically want a g_signal_connect_after_always(), but I can't
|
|
|
|
* find that, so we do this complex 'first-call-parent-then-do-actual-
|
2008-06-27 09:33:32 +00:00
|
|
|
* action' thingy...
|
|
|
|
*/
|
2010-05-25 22:38:44 +00:00
|
|
|
gtk_device_grab_add (button->priv->dock, event->device, TRUE);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_scale_button_update_icon (GtkScaleButton *button)
|
|
|
|
{
|
|
|
|
GtkScaleButtonPrivate *priv;
|
2011-01-05 22:02:10 +00:00
|
|
|
GtkAdjustment *adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
gdouble value;
|
|
|
|
const gchar *name;
|
|
|
|
guint num_icons;
|
|
|
|
|
|
|
|
priv = button->priv;
|
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
if (!priv->icon_list || priv->icon_list[0] == '\0')
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
gtk_image_set_from_stock (GTK_IMAGE (priv->image),
|
2011-01-24 02:50:39 +00:00
|
|
|
GTK_STOCK_MISSING_IMAGE,
|
|
|
|
priv->size);
|
2007-05-19 23:08:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-06-26 17:14:27 +00:00
|
|
|
|
2007-06-10 15:32:02 +00:00
|
|
|
num_icons = g_strv_length (priv->icon_list);
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
/* The 1-icon special case */
|
|
|
|
if (num_icons == 1)
|
|
|
|
{
|
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
|
2011-01-24 02:50:39 +00:00
|
|
|
priv->icon_list[0],
|
|
|
|
priv->size);
|
2007-05-19 23:08:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-05 22:02:10 +00:00
|
|
|
adjustment = priv->adjustment;
|
2007-05-19 23:08:02 +00:00
|
|
|
value = gtk_scale_button_get_value (button);
|
|
|
|
|
|
|
|
/* The 2-icons special case */
|
|
|
|
if (num_icons == 2)
|
|
|
|
{
|
|
|
|
gdouble limit;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
2011-01-05 22:02:10 +00:00
|
|
|
limit = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment)) / 2 + gtk_adjustment_get_lower (adjustment);
|
2007-05-19 23:08:02 +00:00
|
|
|
if (value < limit)
|
2011-01-24 02:50:39 +00:00
|
|
|
name = priv->icon_list[0];
|
2007-05-19 23:08:02 +00:00
|
|
|
else
|
2011-01-24 02:50:39 +00:00
|
|
|
name = priv->icon_list[1];
|
2007-05-19 23:08:02 +00:00
|
|
|
|
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
|
2011-01-24 02:50:39 +00:00
|
|
|
name,
|
|
|
|
priv->size);
|
2007-05-19 23:08:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* With 3 or more icons */
|
2011-01-05 22:02:10 +00:00
|
|
|
if (value == gtk_adjustment_get_lower (adjustment))
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
name = priv->icon_list[0];
|
|
|
|
}
|
2011-01-05 22:02:10 +00:00
|
|
|
else if (value == gtk_adjustment_get_upper (adjustment))
|
2007-05-19 23:08:02 +00:00
|
|
|
{
|
|
|
|
name = priv->icon_list[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdouble step;
|
|
|
|
guint i;
|
|
|
|
|
2011-01-05 22:02:10 +00:00
|
|
|
step = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment)) / (num_icons - 2);
|
|
|
|
i = (guint) ((value - gtk_adjustment_get_lower (adjustment)) / step) + 2;
|
2007-05-19 23:08:02 +00:00
|
|
|
g_assert (i < num_icons);
|
|
|
|
name = priv->icon_list[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
|
2011-01-24 02:50:39 +00:00
|
|
|
name,
|
|
|
|
priv->size);
|
2007-05-19 23:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_scale_button_scale_value_changed (GtkRange *range)
|
|
|
|
{
|
2009-02-19 15:10:34 +00:00
|
|
|
GtkScaleButton *button = GTK_SCALE_BUTTON_SCALE (range)->button;
|
2007-05-19 23:08:02 +00:00
|
|
|
gdouble value;
|
|
|
|
|
2013-03-23 11:17:15 +00:00
|
|
|
/* Avoid a crash when using a GtkScaleButtonScale without a GtkScaleButton,
|
|
|
|
* this can happen while editing gtkscalebutton.ui in Glade
|
|
|
|
*/
|
|
|
|
if (!button)
|
|
|
|
return;
|
|
|
|
|
2007-05-19 23:08:02 +00:00
|
|
|
value = gtk_range_get_value (range);
|
|
|
|
|
|
|
|
gtk_scale_button_update_icon (button);
|
|
|
|
|
|
|
|
g_signal_emit (button, signals[VALUE_CHANGED], 0, value);
|
|
|
|
g_object_notify (G_OBJECT (button), "value");
|
|
|
|
}
|