2010-11-26 13:24:04 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation
|
|
|
|
* Copyright (C) 2010 RedHat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-26 13:24:04 +00:00
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Emmanuele Bassi <ebassi@linux.intel.com>
|
|
|
|
* Matthias Clasen <mclasen@redhat.com>
|
|
|
|
*
|
2010-11-30 21:54:48 +00:00
|
|
|
* Based on similar code from Mx.
|
2010-11-26 13:24:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkswitch
|
2014-02-05 18:07:34 +00:00
|
|
|
* @Short_Description: A “light switch” style toggle
|
2010-11-26 13:24:04 +00:00
|
|
|
* @Title: GtkSwitch
|
|
|
|
* @See_Also: #GtkToggleButton
|
|
|
|
*
|
|
|
|
* #GtkSwitch is a widget that has two states: on or off. The user can control
|
|
|
|
* which state should be active by clicking the empty area, or by dragging the
|
|
|
|
* handle.
|
2014-03-29 17:40:08 +00:00
|
|
|
*
|
|
|
|
* GtkSwitch can also handle situations where the underlying state changes with
|
|
|
|
* a delay. See #GtkSwitch::state-set for details.
|
2015-10-23 03:07:54 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
2015-11-03 18:28:52 +00:00
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
* switch
|
|
|
|
* ╰── slider
|
|
|
|
* ]|
|
|
|
|
*
|
2015-10-23 03:07:54 +00:00
|
|
|
* GtkSwitch has two css nodes, the main node with the name switch and a subnode
|
|
|
|
* named slider. Neither of them is using any style classes.
|
2010-11-26 13:24:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkswitch.h"
|
|
|
|
|
2013-07-20 00:29:11 +00:00
|
|
|
#include "deprecated/gtkactivatable.h"
|
2015-02-16 22:05:05 +00:00
|
|
|
#include "deprecated/gtktoggleaction.h"
|
2010-11-26 13:24:04 +00:00
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkprivate.h"
|
2010-11-29 00:18:56 +00:00
|
|
|
#include "gtkwidget.h"
|
2011-02-25 20:47:03 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2012-01-11 05:10:34 +00:00
|
|
|
#include "gtkapplicationprivate.h"
|
|
|
|
#include "gtkactionable.h"
|
2011-07-02 22:46:04 +00:00
|
|
|
#include "a11y/gtkswitchaccessible.h"
|
2012-08-17 22:26:53 +00:00
|
|
|
#include "gtkactionhelper.h"
|
2015-03-09 05:16:50 +00:00
|
|
|
#include "gtkcsscustomgadgetprivate.h"
|
|
|
|
#include "gtkcssgadgetprivate.h"
|
2019-01-24 22:23:40 +00:00
|
|
|
#include "gtkiconhelperprivate.h"
|
2015-02-16 22:05:05 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
2014-07-18 20:37:18 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2015-10-03 20:20:50 +00:00
|
|
|
#include "gtkcssshadowsvalueprivate.h"
|
2015-12-16 18:48:08 +00:00
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2016-03-28 21:38:22 +00:00
|
|
|
#include "gtkprogresstrackerprivate.h"
|
2016-05-01 04:40:08 +00:00
|
|
|
#include "gtksettingsprivate.h"
|
2011-02-25 20:47:03 +00:00
|
|
|
|
2015-03-03 04:14:24 +00:00
|
|
|
#include "fallback-c89.c"
|
2010-11-26 13:24:04 +00:00
|
|
|
|
|
|
|
#define DEFAULT_SLIDER_WIDTH (36)
|
2015-06-29 22:25:44 +00:00
|
|
|
#define DEFAULT_SLIDER_HEIGHT (22)
|
2010-11-26 13:24:04 +00:00
|
|
|
|
|
|
|
struct _GtkSwitchPrivate
|
|
|
|
{
|
|
|
|
GdkWindow *event_window;
|
|
|
|
GtkAction *action;
|
2012-08-17 22:26:53 +00:00
|
|
|
GtkActionHelper *action_helper;
|
2012-01-11 05:10:34 +00:00
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
GtkGesture *pan_gesture;
|
|
|
|
GtkGesture *multipress_gesture;
|
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
GtkCssGadget *gadget;
|
|
|
|
GtkCssGadget *slider_gadget;
|
2019-01-24 22:23:40 +00:00
|
|
|
GtkCssGadget *on_gadget;
|
|
|
|
GtkCssGadget *off_gadget;
|
2015-02-16 22:05:05 +00:00
|
|
|
|
2015-02-16 05:25:44 +00:00
|
|
|
double handle_pos;
|
2014-08-03 08:20:38 +00:00
|
|
|
guint tick_id;
|
2016-03-28 21:38:22 +00:00
|
|
|
GtkProgressTracker tracker;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2014-03-29 17:40:08 +00:00
|
|
|
guint state : 1;
|
2010-11-26 13:24:04 +00:00
|
|
|
guint is_active : 1;
|
|
|
|
guint in_switch : 1;
|
|
|
|
guint use_action_appearance : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_ACTIVE,
|
2014-03-29 17:40:08 +00:00
|
|
|
PROP_STATE,
|
2010-11-26 13:24:04 +00:00
|
|
|
PROP_RELATED_ACTION,
|
|
|
|
PROP_USE_ACTION_APPEARANCE,
|
2012-01-11 05:10:34 +00:00
|
|
|
LAST_PROP,
|
|
|
|
PROP_ACTION_NAME,
|
|
|
|
PROP_ACTION_TARGET
|
2010-11-26 13:24:04 +00:00
|
|
|
};
|
|
|
|
|
2011-02-25 20:47:03 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ACTIVATE,
|
2014-03-29 17:40:08 +00:00
|
|
|
STATE_SET,
|
2011-02-25 20:47:03 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
static GParamSpec *switch_props[LAST_PROP] = { NULL, };
|
|
|
|
|
2012-01-11 05:10:34 +00:00
|
|
|
static void gtk_switch_actionable_iface_init (GtkActionableInterface *iface);
|
2010-11-26 13:24:04 +00:00
|
|
|
static void gtk_switch_activatable_interface_init (GtkActivatableIface *iface);
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkSwitch, gtk_switch, GTK_TYPE_WIDGET,
|
2013-06-27 19:02:52 +00:00
|
|
|
G_ADD_PRIVATE (GtkSwitch)
|
2012-01-11 05:10:34 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIONABLE,
|
|
|
|
gtk_switch_actionable_iface_init)
|
2010-11-26 13:24:04 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
|
|
|
|
gtk_switch_activatable_interface_init));
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2014-08-03 08:20:38 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_end_toggle_animation (GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = sw->priv;
|
|
|
|
|
|
|
|
if (priv->tick_id != 0)
|
|
|
|
{
|
2014-09-23 15:22:12 +00:00
|
|
|
gtk_widget_remove_tick_callback (GTK_WIDGET (sw), priv->tick_id);
|
2014-08-03 08:20:38 +00:00
|
|
|
priv->tick_id = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-23 15:22:12 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_switch_on_frame_clock_update (GtkWidget *widget,
|
|
|
|
GdkFrameClock *clock,
|
|
|
|
gpointer user_data)
|
2014-08-03 08:20:38 +00:00
|
|
|
{
|
2014-09-23 15:22:12 +00:00
|
|
|
GtkSwitch *sw = GTK_SWITCH (widget);
|
2014-08-03 08:20:38 +00:00
|
|
|
GtkSwitchPrivate *priv = sw->priv;
|
|
|
|
|
2016-03-28 21:38:22 +00:00
|
|
|
gtk_progress_tracker_advance_frame (&priv->tracker,
|
|
|
|
gdk_frame_clock_get_frame_time (clock));
|
2014-08-03 08:20:38 +00:00
|
|
|
|
2016-03-28 21:38:22 +00:00
|
|
|
if (gtk_progress_tracker_get_state (&priv->tracker) != GTK_PROGRESS_STATE_AFTER)
|
2014-08-03 08:20:38 +00:00
|
|
|
{
|
2015-02-16 05:25:44 +00:00
|
|
|
if (priv->is_active)
|
2016-03-28 21:38:22 +00:00
|
|
|
priv->handle_pos = 1.0 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE);
|
2015-02-16 05:25:44 +00:00
|
|
|
else
|
2016-03-28 21:38:22 +00:00
|
|
|
priv->handle_pos = gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE);
|
2014-08-03 08:20:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_switch_set_active (sw, !priv->is_active);
|
|
|
|
}
|
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_widget_queue_allocate (GTK_WIDGET (sw));
|
2014-09-23 15:22:12 +00:00
|
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
2014-08-03 08:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ANIMATION_DURATION 100
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_begin_toggle_animation (GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = sw->priv;
|
|
|
|
|
2016-05-01 04:40:08 +00:00
|
|
|
if (gtk_settings_get_enable_animations (gtk_widget_get_settings (GTK_WIDGET (sw))))
|
2014-08-03 08:20:38 +00:00
|
|
|
{
|
2016-03-28 21:38:22 +00:00
|
|
|
gtk_progress_tracker_start (&priv->tracker, 1000 * ANIMATION_DURATION, 0, 1.0);
|
2014-08-03 08:20:38 +00:00
|
|
|
if (priv->tick_id == 0)
|
2014-09-23 15:22:12 +00:00
|
|
|
priv->tick_id = gtk_widget_add_tick_callback (GTK_WIDGET (sw),
|
|
|
|
gtk_switch_on_frame_clock_update,
|
|
|
|
NULL, NULL);
|
2014-08-03 08:20:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_switch_set_active (sw, !priv->is_active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
|
|
|
|
gint n_press,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GtkSwitch *sw)
|
2010-11-26 13:24:04 +00:00
|
|
|
{
|
2014-05-19 14:08:56 +00:00
|
|
|
GtkSwitchPrivate *priv = sw->priv;
|
2010-11-26 13:24:04 +00:00
|
|
|
GtkAllocation allocation;
|
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (sw), &allocation);
|
|
|
|
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
2019-12-06 13:52:11 +00:00
|
|
|
priv->in_switch = TRUE;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
/* If the press didn't happen in the draggable handle,
|
|
|
|
* cancel the pan gesture right away
|
|
|
|
*/
|
2017-10-05 08:16:18 +00:00
|
|
|
if ((priv->is_active && x <= allocation.width / 2.0) ||
|
|
|
|
(!priv->is_active && x > allocation.width / 2.0))
|
2014-05-19 14:08:56 +00:00
|
|
|
gtk_gesture_set_state (priv->pan_gesture, GTK_EVENT_SEQUENCE_DENIED);
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_multipress_gesture_released (GtkGestureMultiPress *gesture,
|
|
|
|
gint n_press,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GtkSwitch *sw)
|
2010-11-26 13:24:04 +00:00
|
|
|
{
|
2014-05-19 14:08:56 +00:00
|
|
|
GtkSwitchPrivate *priv = sw->priv;
|
|
|
|
GdkEventSequence *sequence;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
if (priv->in_switch &&
|
|
|
|
gtk_gesture_handles_sequence (GTK_GESTURE (gesture), sequence))
|
2014-08-03 08:20:38 +00:00
|
|
|
gtk_switch_begin_toggle_animation (sw);
|
2019-12-06 13:52:11 +00:00
|
|
|
|
|
|
|
priv->in_switch = FALSE;
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_pan_gesture_pan (GtkGesturePan *gesture,
|
|
|
|
GtkPanDirection direction,
|
|
|
|
gdouble offset,
|
|
|
|
GtkSwitch *sw)
|
2010-11-26 13:24:04 +00:00
|
|
|
{
|
2014-05-19 14:08:56 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (sw);
|
|
|
|
GtkSwitchPrivate *priv = sw->priv;
|
2015-02-16 05:25:44 +00:00
|
|
|
gint width;
|
2014-05-19 14:08:56 +00:00
|
|
|
|
|
|
|
if (direction == GTK_PAN_DIRECTION_LEFT)
|
|
|
|
offset = -offset;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
|
|
|
|
2015-02-16 04:22:00 +00:00
|
|
|
width = gtk_widget_get_allocated_width (widget);
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2015-02-16 04:22:00 +00:00
|
|
|
if (priv->is_active)
|
2015-02-16 05:25:44 +00:00
|
|
|
offset += width / 2;
|
|
|
|
|
|
|
|
offset /= width / 2;
|
2014-05-19 14:08:56 +00:00
|
|
|
/* constrain the handle within the trough width */
|
2015-02-16 05:25:44 +00:00
|
|
|
priv->handle_pos = CLAMP (offset, 0, 1.0);
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
/* we need to redraw the handle */
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_widget_queue_allocate (widget);
|
2014-05-19 14:08:56 +00:00
|
|
|
}
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_pan_gesture_drag_end (GtkGestureDrag *gesture,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = sw->priv;
|
|
|
|
GdkEventSequence *sequence;
|
|
|
|
GtkAllocation allocation;
|
2015-02-16 05:25:44 +00:00
|
|
|
gboolean active;
|
2011-01-11 11:34:23 +00:00
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
|
2011-01-11 11:34:23 +00:00
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
if (gtk_gesture_get_sequence_state (GTK_GESTURE (gesture), sequence) == GTK_EVENT_SEQUENCE_CLAIMED)
|
2010-11-26 13:24:04 +00:00
|
|
|
{
|
2014-05-19 14:08:56 +00:00
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (sw), &allocation);
|
2010-11-26 13:24:04 +00:00
|
|
|
|
|
|
|
/* if half the handle passed the middle of the switch, then we
|
|
|
|
* consider it to be on
|
|
|
|
*/
|
2015-02-16 05:25:44 +00:00
|
|
|
active = priv->handle_pos >= 0.5;
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
2014-05-19 14:08:56 +00:00
|
|
|
else if (!gtk_gesture_handles_sequence (priv->multipress_gesture, sequence))
|
|
|
|
active = priv->is_active;
|
|
|
|
else
|
|
|
|
return;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2015-02-16 05:25:44 +00:00
|
|
|
priv->handle_pos = active ? 1.0 : 0.0;
|
2014-05-19 14:08:56 +00:00
|
|
|
gtk_switch_set_active (sw, active);
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_widget_queue_allocate (GTK_WIDGET (sw));
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_switch_enter (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
|
|
|
|
|
|
|
|
if (event->window == priv->event_window)
|
2014-06-22 01:34:50 +00:00
|
|
|
{
|
|
|
|
priv->in_switch = TRUE;
|
2014-10-13 02:23:02 +00:00
|
|
|
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_PRELIGHT, FALSE);
|
2014-06-22 01:34:50 +00:00
|
|
|
}
|
2010-11-26 13:24:04 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_switch_leave (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
|
|
|
|
|
|
|
|
if (event->window == priv->event_window)
|
2014-06-22 01:34:50 +00:00
|
|
|
{
|
|
|
|
priv->in_switch = FALSE;
|
2014-10-13 02:23:02 +00:00
|
|
|
gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_PRELIGHT);
|
2014-06-22 01:34:50 +00:00
|
|
|
}
|
2010-11-26 13:24:04 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-25 20:47:03 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_activate (GtkSwitch *sw)
|
2010-11-26 13:24:04 +00:00
|
|
|
{
|
2014-08-04 11:56:39 +00:00
|
|
|
gtk_switch_begin_toggle_animation (sw);
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_switch_get_slider_size (GtkCssGadget *gadget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural,
|
|
|
|
gint *minimum_baseline,
|
|
|
|
gint *natural_baseline,
|
|
|
|
gpointer unused)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
|
2015-12-16 18:48:08 +00:00
|
|
|
gdouble min_size;
|
2015-03-09 05:16:50 +00:00
|
|
|
|
2015-12-16 18:48:08 +00:00
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
2015-03-09 05:16:50 +00:00
|
|
|
{
|
2015-12-16 18:48:08 +00:00
|
|
|
min_size = _gtk_css_number_value_get (gtk_css_style_get_value (gtk_css_gadget_get_style (gadget), GTK_CSS_PROPERTY_MIN_WIDTH), 100);
|
|
|
|
|
|
|
|
if (min_size > 0.0)
|
|
|
|
*minimum = 0;
|
|
|
|
else
|
|
|
|
gtk_widget_style_get (widget, "slider-width", minimum, NULL);
|
2015-03-09 05:16:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-16 18:48:08 +00:00
|
|
|
min_size = _gtk_css_number_value_get (gtk_css_style_get_value (gtk_css_gadget_get_style (gadget), GTK_CSS_PROPERTY_MIN_HEIGHT), 100);
|
|
|
|
|
|
|
|
if (min_size > 0.0)
|
|
|
|
*minimum = 0;
|
|
|
|
else
|
|
|
|
gtk_widget_style_get (widget, "slider-height", minimum, NULL);
|
2015-03-09 05:16:50 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 18:48:08 +00:00
|
|
|
*natural = *minimum;
|
2015-03-09 05:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_get_content_size (GtkCssGadget *gadget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural,
|
|
|
|
gint *minimum_baseline,
|
|
|
|
gint *natural_baseline,
|
|
|
|
gpointer unused)
|
2010-11-26 13:24:04 +00:00
|
|
|
{
|
2015-03-09 05:16:50 +00:00
|
|
|
GtkWidget *widget;
|
2015-02-16 22:05:05 +00:00
|
|
|
GtkSwitch *self;
|
|
|
|
GtkSwitchPrivate *priv;
|
2015-03-09 05:16:50 +00:00
|
|
|
gint slider_minimum, slider_natural;
|
2019-01-24 22:23:40 +00:00
|
|
|
gint on_minimum, on_natural;
|
|
|
|
gint off_minimum, off_natural;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
widget = gtk_css_gadget_get_owner (gadget);
|
2015-02-16 22:05:05 +00:00
|
|
|
self = GTK_SWITCH (widget);
|
|
|
|
priv = self->priv;
|
2010-12-28 17:59:45 +00:00
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_css_gadget_get_preferred_size (priv->slider_gadget,
|
|
|
|
orientation,
|
|
|
|
-1,
|
|
|
|
&slider_minimum, &slider_natural,
|
|
|
|
NULL, NULL);
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2019-01-24 22:23:40 +00:00
|
|
|
gtk_css_gadget_get_preferred_size (priv->on_gadget,
|
|
|
|
orientation,
|
|
|
|
-1,
|
|
|
|
&on_minimum, &on_natural,
|
|
|
|
NULL, NULL);
|
|
|
|
gtk_css_gadget_get_preferred_size (priv->off_gadget,
|
|
|
|
orientation,
|
|
|
|
-1,
|
|
|
|
&off_minimum, &off_natural,
|
|
|
|
NULL, NULL);
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
2019-01-24 22:23:40 +00:00
|
|
|
*minimum = 2 * MAX (slider_minimum, MAX (on_minimum, off_minimum));
|
|
|
|
*natural = 2 * MAX (slider_natural, MAX (on_natural, off_natural));
|
2015-03-09 05:16:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-24 22:23:40 +00:00
|
|
|
*minimum = MAX (slider_minimum, MAX (on_minimum, off_minimum));
|
|
|
|
*natural = MAX (slider_natural, MAX (on_natural, off_natural));
|
2015-03-09 05:16:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
|
|
|
gtk_css_gadget_get_preferred_size (GTK_SWITCH (widget)->priv->gadget,
|
|
|
|
GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
-1,
|
|
|
|
minimum, natural,
|
|
|
|
NULL, NULL);
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_css_gadget_get_preferred_size (GTK_SWITCH (widget)->priv->gadget,
|
|
|
|
GTK_ORIENTATION_VERTICAL,
|
|
|
|
-1,
|
|
|
|
minimum, natural,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_allocate_contents (GtkCssGadget *gadget,
|
|
|
|
const GtkAllocation *allocation,
|
|
|
|
int baseline,
|
|
|
|
GtkAllocation *out_clip,
|
|
|
|
gpointer unused)
|
|
|
|
{
|
|
|
|
GtkSwitch *self = GTK_SWITCH (gtk_css_gadget_get_owner (gadget));
|
|
|
|
GtkSwitchPrivate *priv = self->priv;
|
2019-01-24 22:23:40 +00:00
|
|
|
GtkAllocation child_alloc;
|
2019-01-30 17:31:07 +00:00
|
|
|
GtkAllocation on_clip, off_clip;
|
|
|
|
|
2019-01-24 22:23:40 +00:00
|
|
|
child_alloc.x = allocation->x + round (priv->handle_pos * (allocation->width - allocation->width / 2));
|
|
|
|
child_alloc.y = allocation->y;
|
|
|
|
child_alloc.width = allocation->width / 2;
|
|
|
|
child_alloc.height = allocation->height;
|
2015-03-09 05:16:50 +00:00
|
|
|
|
|
|
|
gtk_css_gadget_allocate (priv->slider_gadget,
|
2019-01-24 22:23:40 +00:00
|
|
|
&child_alloc,
|
|
|
|
baseline,
|
|
|
|
out_clip);
|
|
|
|
|
|
|
|
child_alloc.x = allocation->x;
|
|
|
|
|
|
|
|
gtk_css_gadget_allocate (priv->on_gadget,
|
|
|
|
&child_alloc,
|
|
|
|
baseline,
|
2019-01-30 17:31:07 +00:00
|
|
|
&on_clip);
|
|
|
|
|
|
|
|
gdk_rectangle_union (out_clip, &on_clip, out_clip);
|
2019-01-24 22:23:40 +00:00
|
|
|
|
|
|
|
child_alloc.x = allocation->x + allocation->width - child_alloc.width;
|
|
|
|
gtk_css_gadget_allocate (priv->off_gadget,
|
|
|
|
&child_alloc,
|
2015-03-09 05:16:50 +00:00
|
|
|
baseline,
|
2019-01-30 17:31:07 +00:00
|
|
|
&off_clip);
|
|
|
|
|
|
|
|
gdk_rectangle_union (out_clip, &off_clip, out_clip);
|
2016-01-12 20:36:37 +00:00
|
|
|
|
|
|
|
if (gtk_widget_get_realized (GTK_WIDGET (self)))
|
|
|
|
{
|
|
|
|
GtkAllocation border_allocation;
|
|
|
|
gtk_css_gadget_get_border_allocation (gadget, &border_allocation, NULL);
|
|
|
|
gdk_window_move_resize (priv->event_window,
|
|
|
|
border_allocation.x,
|
|
|
|
border_allocation.y,
|
|
|
|
border_allocation.width,
|
|
|
|
border_allocation.height);
|
|
|
|
}
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
|
2015-10-03 20:20:50 +00:00
|
|
|
GtkAllocation clip;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
|
|
|
gtk_widget_set_allocation (widget, allocation);
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_css_gadget_allocate (priv->gadget,
|
|
|
|
allocation,
|
|
|
|
gtk_widget_get_allocated_baseline (widget),
|
|
|
|
&clip);
|
2016-01-12 20:36:37 +00:00
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_widget_set_clip (widget, &clip);
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
|
|
|
|
GdkWindow *parent_window;
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
gint attributes_mask;
|
|
|
|
GtkAllocation allocation;
|
|
|
|
|
|
|
|
gtk_widget_set_realized (widget, TRUE);
|
|
|
|
parent_window = gtk_widget_get_parent_window (widget);
|
|
|
|
gtk_widget_set_window (widget, parent_window);
|
|
|
|
g_object_ref (parent_window);
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
attributes.wclass = GDK_INPUT_ONLY;
|
|
|
|
attributes.x = allocation.x;
|
|
|
|
attributes.y = allocation.y;
|
|
|
|
attributes.width = allocation.width;
|
|
|
|
attributes.height = allocation.height;
|
|
|
|
attributes.event_mask = gtk_widget_get_events (widget);
|
|
|
|
attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK |
|
|
|
|
GDK_ENTER_NOTIFY_MASK |
|
|
|
|
GDK_LEAVE_NOTIFY_MASK);
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y;
|
|
|
|
|
|
|
|
priv->event_window = gdk_window_new (parent_window,
|
|
|
|
&attributes,
|
|
|
|
attributes_mask);
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_register_window (widget, priv->event_window);
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_unrealize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
|
|
|
|
|
|
|
|
if (priv->event_window != NULL)
|
|
|
|
{
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_unregister_window (widget, priv->event_window);
|
2010-11-26 13:24:04 +00:00
|
|
|
gdk_window_destroy (priv->event_window);
|
|
|
|
priv->event_window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_switch_parent_class)->unrealize (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_switch_parent_class)->map (widget);
|
|
|
|
|
|
|
|
if (priv->event_window)
|
|
|
|
gdk_window_show (priv->event_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
|
|
|
|
|
|
|
|
if (priv->event_window)
|
|
|
|
gdk_window_hide (priv->event_window);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_switch_parent_class)->unmap (widget);
|
|
|
|
}
|
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_switch_render_slider (GtkCssGadget *gadget,
|
|
|
|
cairo_t *cr,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
gpointer data)
|
2010-11-26 13:24:04 +00:00
|
|
|
{
|
2015-03-09 05:16:50 +00:00
|
|
|
return gtk_widget_has_visible_focus (gtk_css_gadget_get_owner (gadget));
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_switch_render_trough (GtkCssGadget *gadget,
|
|
|
|
cairo_t *cr,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
gpointer data)
|
2010-11-26 13:24:04 +00:00
|
|
|
{
|
2015-03-09 05:16:50 +00:00
|
|
|
GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
|
2010-11-26 13:24:04 +00:00
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
|
|
|
|
|
2019-01-24 22:23:40 +00:00
|
|
|
gtk_css_gadget_draw (priv->on_gadget, cr);
|
|
|
|
gtk_css_gadget_draw (priv->off_gadget, cr);
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_css_gadget_draw (priv->slider_gadget, cr);
|
2010-12-28 17:59:45 +00:00
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_switch_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
gtk_css_gadget_draw (GTK_SWITCH (widget)->priv->gadget, cr);
|
2013-04-15 20:24:48 +00:00
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:23:40 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_state_flags_changed (GtkWidget *widget,
|
|
|
|
GtkStateFlags previous_state_flags)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
|
|
|
|
GtkStateFlags state = gtk_widget_get_state_flags (widget);
|
|
|
|
|
|
|
|
gtk_css_gadget_set_state (priv->gadget, state);
|
|
|
|
gtk_css_gadget_set_state (priv->slider_gadget, state);
|
|
|
|
gtk_css_gadget_set_state (priv->on_gadget, state);
|
|
|
|
gtk_css_gadget_set_state (priv->off_gadget, state);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_switch_parent_class)->state_flags_changed (widget, previous_state_flags);
|
|
|
|
}
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_set_related_action (GtkSwitch *sw,
|
|
|
|
GtkAction *action)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = sw->priv;
|
|
|
|
|
|
|
|
if (priv->action == action)
|
|
|
|
return;
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (sw), action);
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
|
|
|
priv->action = action;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_set_use_action_appearance (GtkSwitch *sw,
|
|
|
|
gboolean use_appearance)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = sw->priv;
|
|
|
|
|
|
|
|
if (priv->use_action_appearance != use_appearance)
|
|
|
|
{
|
|
|
|
priv->use_action_appearance = use_appearance;
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (sw), priv->action);
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-11 05:10:34 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_set_action_name (GtkActionable *actionable,
|
|
|
|
const gchar *action_name)
|
|
|
|
{
|
|
|
|
GtkSwitch *sw = GTK_SWITCH (actionable);
|
|
|
|
|
2012-08-17 22:26:53 +00:00
|
|
|
if (!sw->priv->action_helper)
|
|
|
|
sw->priv->action_helper = gtk_action_helper_new (actionable);
|
2012-01-11 05:10:34 +00:00
|
|
|
|
2012-08-17 22:26:53 +00:00
|
|
|
gtk_action_helper_set_action_name (sw->priv->action_helper, action_name);
|
2012-01-11 05:10:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_set_action_target_value (GtkActionable *actionable,
|
|
|
|
GVariant *action_target)
|
|
|
|
{
|
|
|
|
GtkSwitch *sw = GTK_SWITCH (actionable);
|
|
|
|
|
2012-08-17 22:26:53 +00:00
|
|
|
if (!sw->priv->action_helper)
|
|
|
|
sw->priv->action_helper = gtk_action_helper_new (actionable);
|
2012-01-11 05:10:34 +00:00
|
|
|
|
2012-08-17 22:26:53 +00:00
|
|
|
gtk_action_helper_set_action_target_value (sw->priv->action_helper, action_target);
|
2012-01-11 05:10:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
gtk_switch_get_action_name (GtkActionable *actionable)
|
|
|
|
{
|
|
|
|
GtkSwitch *sw = GTK_SWITCH (actionable);
|
|
|
|
|
2012-08-17 22:26:53 +00:00
|
|
|
return gtk_action_helper_get_action_name (sw->priv->action_helper);
|
2012-01-11 05:10:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GVariant *
|
|
|
|
gtk_switch_get_action_target_value (GtkActionable *actionable)
|
|
|
|
{
|
|
|
|
GtkSwitch *sw = GTK_SWITCH (actionable);
|
|
|
|
|
2012-08-17 22:26:53 +00:00
|
|
|
return gtk_action_helper_get_action_target_value (sw->priv->action_helper);
|
2012-01-11 05:10:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_actionable_iface_init (GtkActionableInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_action_name = gtk_switch_get_action_name;
|
|
|
|
iface->set_action_name = gtk_switch_set_action_name;
|
|
|
|
iface->get_action_target_value = gtk_switch_get_action_target_value;
|
|
|
|
iface->set_action_target_value = gtk_switch_set_action_target_value;
|
|
|
|
}
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_set_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkSwitch *sw = GTK_SWITCH (gobject);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ACTIVE:
|
|
|
|
gtk_switch_set_active (sw, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2014-03-29 17:40:08 +00:00
|
|
|
case PROP_STATE:
|
|
|
|
gtk_switch_set_state (sw, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
case PROP_RELATED_ACTION:
|
|
|
|
gtk_switch_set_related_action (sw, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_USE_ACTION_APPEARANCE:
|
|
|
|
gtk_switch_set_use_action_appearance (sw, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2012-01-11 05:10:34 +00:00
|
|
|
case PROP_ACTION_NAME:
|
|
|
|
gtk_switch_set_action_name (GTK_ACTIONABLE (sw), g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ACTION_TARGET:
|
|
|
|
gtk_switch_set_action_target_value (GTK_ACTIONABLE (sw), g_value_get_variant (value));
|
|
|
|
break;
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (gobject)->priv;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ACTIVE:
|
|
|
|
g_value_set_boolean (value, priv->is_active);
|
|
|
|
break;
|
|
|
|
|
2014-03-29 17:40:08 +00:00
|
|
|
case PROP_STATE:
|
|
|
|
g_value_set_boolean (value, priv->state);
|
|
|
|
break;
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
case PROP_RELATED_ACTION:
|
|
|
|
g_value_set_object (value, priv->action);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_USE_ACTION_APPEARANCE:
|
|
|
|
g_value_set_boolean (value, priv->use_action_appearance);
|
|
|
|
break;
|
|
|
|
|
2012-01-11 05:10:34 +00:00
|
|
|
case PROP_ACTION_NAME:
|
2012-08-17 22:26:53 +00:00
|
|
|
g_value_set_string (value, gtk_action_helper_get_action_name (priv->action_helper));
|
2012-01-11 05:10:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ACTION_TARGET:
|
2012-08-17 22:26:53 +00:00
|
|
|
g_value_set_variant (value, gtk_action_helper_get_action_target_value (priv->action_helper));
|
2012-01-11 05:10:34 +00:00
|
|
|
break;
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv = GTK_SWITCH (object)->priv;
|
|
|
|
|
2012-08-17 22:26:53 +00:00
|
|
|
g_clear_object (&priv->action_helper);
|
2012-01-11 05:10:34 +00:00
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
if (priv->action)
|
|
|
|
{
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (object), NULL);
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
priv->action = NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
g_clear_object (&priv->gadget);
|
|
|
|
g_clear_object (&priv->slider_gadget);
|
2019-01-24 22:23:40 +00:00
|
|
|
g_clear_object (&priv->on_gadget);
|
|
|
|
g_clear_object (&priv->off_gadget);
|
2015-03-09 05:16:50 +00:00
|
|
|
|
2014-05-26 12:02:30 +00:00
|
|
|
g_clear_object (&priv->pan_gesture);
|
|
|
|
g_clear_object (&priv->multipress_gesture);
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
G_OBJECT_CLASS (gtk_switch_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2014-08-04 12:25:10 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
gtk_switch_end_toggle_animation (GTK_SWITCH (object));
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_switch_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2014-03-29 17:40:08 +00:00
|
|
|
static gboolean
|
|
|
|
state_set (GtkSwitch *sw, gboolean state)
|
|
|
|
{
|
|
|
|
if (sw->priv->action_helper)
|
|
|
|
gtk_action_helper_activate (sw->priv->action_helper);
|
|
|
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
if (sw->priv->action)
|
|
|
|
gtk_action_activate (sw->priv->action);
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
|
|
|
gtk_switch_set_state (sw, state);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_class_init (GtkSwitchClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
gpointer activatable_iface;
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
activatable_iface = g_type_default_interface_peek (GTK_TYPE_ACTIVATABLE);
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
switch_props[PROP_RELATED_ACTION] =
|
|
|
|
g_param_spec_override ("related-action",
|
|
|
|
g_object_interface_find_property (activatable_iface,
|
|
|
|
"related-action"));
|
|
|
|
|
|
|
|
switch_props[PROP_USE_ACTION_APPEARANCE] =
|
|
|
|
g_param_spec_override ("use-action-appearance",
|
|
|
|
g_object_interface_find_property (activatable_iface,
|
|
|
|
"use-action-appearance"));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkSwitch:active:
|
|
|
|
*
|
|
|
|
* Whether the #GtkSwitch widget is in its on or off state.
|
|
|
|
*/
|
|
|
|
switch_props[PROP_ACTIVE] =
|
|
|
|
g_param_spec_boolean ("active",
|
|
|
|
P_("Active"),
|
|
|
|
P_("Whether the switch is on or off"),
|
|
|
|
FALSE,
|
2014-06-09 15:48:09 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2014-03-29 17:40:08 +00:00
|
|
|
/**
|
|
|
|
* GtkSwitch:state:
|
|
|
|
*
|
|
|
|
* The backend state that is controlled by the switch.
|
|
|
|
* See #GtkSwitch::state-set for details.
|
|
|
|
*
|
|
|
|
* Since: 3.14
|
|
|
|
*/
|
|
|
|
switch_props[PROP_STATE] =
|
|
|
|
g_param_spec_boolean ("state",
|
|
|
|
P_("State"),
|
|
|
|
P_("The backend state"),
|
|
|
|
FALSE,
|
2014-06-09 15:48:09 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2014-03-29 17:40:08 +00:00
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
gobject_class->set_property = gtk_switch_set_property;
|
|
|
|
gobject_class->get_property = gtk_switch_get_property;
|
|
|
|
gobject_class->dispose = gtk_switch_dispose;
|
2014-08-04 12:25:10 +00:00
|
|
|
gobject_class->finalize = gtk_switch_finalize;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
|
|
|
g_object_class_install_properties (gobject_class, LAST_PROP, switch_props);
|
|
|
|
|
|
|
|
widget_class->get_preferred_width = gtk_switch_get_preferred_width;
|
|
|
|
widget_class->get_preferred_height = gtk_switch_get_preferred_height;
|
|
|
|
widget_class->size_allocate = gtk_switch_size_allocate;
|
|
|
|
widget_class->realize = gtk_switch_realize;
|
|
|
|
widget_class->unrealize = gtk_switch_unrealize;
|
|
|
|
widget_class->map = gtk_switch_map;
|
|
|
|
widget_class->unmap = gtk_switch_unmap;
|
|
|
|
widget_class->draw = gtk_switch_draw;
|
|
|
|
widget_class->enter_notify_event = gtk_switch_enter;
|
|
|
|
widget_class->leave_notify_event = gtk_switch_leave;
|
2019-01-24 22:23:40 +00:00
|
|
|
widget_class->state_flags_changed = gtk_switch_state_flags_changed;
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2011-02-25 20:47:03 +00:00
|
|
|
klass->activate = gtk_switch_activate;
|
2014-03-29 17:40:08 +00:00
|
|
|
klass->state_set = state_set;
|
2011-02-25 20:47:03 +00:00
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
/**
|
|
|
|
* GtkSwitch:slider-width:
|
|
|
|
*
|
|
|
|
* The minimum width of the #GtkSwitch handle, in pixels.
|
2015-12-16 18:48:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.20: Use the CSS min-width property instead.
|
2010-11-26 13:24:04 +00:00
|
|
|
*/
|
|
|
|
gtk_widget_class_install_style_property (widget_class,
|
|
|
|
g_param_spec_int ("slider-width",
|
|
|
|
P_("Slider Width"),
|
|
|
|
P_("The minimum width of the handle"),
|
|
|
|
DEFAULT_SLIDER_WIDTH, G_MAXINT,
|
|
|
|
DEFAULT_SLIDER_WIDTH,
|
2015-12-16 18:48:08 +00:00
|
|
|
GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
|
2011-02-25 20:47:03 +00:00
|
|
|
|
2015-06-29 22:25:44 +00:00
|
|
|
/**
|
|
|
|
* GtkSwitch:slider-height:
|
|
|
|
*
|
|
|
|
* The minimum height of the #GtkSwitch handle, in pixels.
|
|
|
|
*
|
|
|
|
* Since: 3.18
|
2015-12-16 18:48:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.20: Use the CSS min-height property instead.
|
2015-06-29 22:25:44 +00:00
|
|
|
*/
|
|
|
|
gtk_widget_class_install_style_property (widget_class,
|
|
|
|
g_param_spec_int ("slider-height",
|
|
|
|
P_("Slider Height"),
|
|
|
|
P_("The minimum height of the handle"),
|
|
|
|
DEFAULT_SLIDER_HEIGHT, G_MAXINT,
|
|
|
|
DEFAULT_SLIDER_HEIGHT,
|
2015-12-16 18:48:08 +00:00
|
|
|
GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
|
2015-06-29 22:25:44 +00:00
|
|
|
|
2011-02-25 20:47:03 +00:00
|
|
|
/**
|
|
|
|
* GtkSwitch::activate:
|
|
|
|
* @widget: the object which received the signal.
|
|
|
|
*
|
|
|
|
* The ::activate signal on GtkSwitch is an action signal and
|
|
|
|
* emitting it causes the switch to animate.
|
|
|
|
* Applications should never connect to this signal, but use the
|
|
|
|
* notify::active signal.
|
|
|
|
*/
|
|
|
|
signals[ACTIVATE] =
|
|
|
|
g_signal_new (I_("activate"),
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET (GtkSwitchClass, activate),
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
NULL,
|
2011-02-25 20:47:03 +00:00
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
widget_class->activate_signal = signals[ACTIVATE];
|
|
|
|
|
2014-03-29 17:40:08 +00:00
|
|
|
/**
|
|
|
|
* GtkSwitch::state-set:
|
|
|
|
* @widget: the object on which the signal was emitted
|
2014-06-29 22:35:31 +00:00
|
|
|
* @state: the new state of the switch
|
2014-03-29 17:40:08 +00:00
|
|
|
*
|
|
|
|
* The ::state-set signal on GtkSwitch is emitted to change the underlying
|
|
|
|
* state. It is emitted when the user changes the switch position. The
|
2016-02-09 07:05:16 +00:00
|
|
|
* default handler keeps the state in sync with the #GtkSwitch:active
|
2014-03-29 17:40:08 +00:00
|
|
|
* property.
|
|
|
|
*
|
|
|
|
* To implement delayed state change, applications can connect to this signal,
|
|
|
|
* initiate the change of the underlying state, and call gtk_switch_set_state()
|
|
|
|
* when the underlying state change is complete. The signal handler should
|
|
|
|
* return %TRUE to prevent the default handler from running.
|
|
|
|
*
|
|
|
|
* Visually, the underlying state is represented by the trough color of
|
|
|
|
* the switch, while the #GtkSwitch:active property is represented by the
|
|
|
|
* position of the switch.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE to stop the signal emission
|
|
|
|
*
|
|
|
|
* Since: 3.14
|
|
|
|
*/
|
|
|
|
signals[STATE_SET] =
|
|
|
|
g_signal_new (I_("state-set"),
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkSwitchClass, state_set),
|
|
|
|
_gtk_boolean_handled_accumulator, NULL,
|
|
|
|
_gtk_marshal_BOOLEAN__BOOLEAN,
|
|
|
|
G_TYPE_BOOLEAN, 1,
|
|
|
|
G_TYPE_BOOLEAN);
|
2019-05-31 22:49:32 +00:00
|
|
|
g_signal_set_va_marshaller (signals[STATE_SET],
|
|
|
|
G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
_gtk_marshal_BOOLEAN__BOOLEANv);
|
2014-03-29 17:40:08 +00:00
|
|
|
|
2012-01-11 05:10:34 +00:00
|
|
|
g_object_class_override_property (gobject_class, PROP_ACTION_NAME, "action-name");
|
|
|
|
g_object_class_override_property (gobject_class, PROP_ACTION_TARGET, "action-target");
|
|
|
|
|
2011-07-02 22:46:04 +00:00
|
|
|
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SWITCH_ACCESSIBLE);
|
2013-09-11 16:37:26 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_TOGGLE_BUTTON);
|
2015-10-23 01:40:31 +00:00
|
|
|
|
|
|
|
gtk_widget_class_set_css_name (widget_class, "switch");
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_init (GtkSwitch *self)
|
|
|
|
{
|
2015-02-16 15:58:17 +00:00
|
|
|
GtkSwitchPrivate *priv;
|
2014-05-19 14:08:56 +00:00
|
|
|
GtkGesture *gesture;
|
2015-02-16 22:05:05 +00:00
|
|
|
GtkCssNode *widget_node;
|
2014-05-19 14:08:56 +00:00
|
|
|
|
2015-02-16 15:58:17 +00:00
|
|
|
priv = self->priv = gtk_switch_get_instance_private (self);
|
|
|
|
|
|
|
|
priv->use_action_appearance = TRUE;
|
2010-11-26 13:24:04 +00:00
|
|
|
gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
|
|
|
|
gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
|
2014-05-19 14:08:56 +00:00
|
|
|
|
2015-02-16 22:05:05 +00:00
|
|
|
widget_node = gtk_widget_get_css_node (GTK_WIDGET (self));
|
2015-03-09 05:16:50 +00:00
|
|
|
priv->gadget = gtk_css_custom_gadget_new_for_node (widget_node,
|
|
|
|
GTK_WIDGET (self),
|
|
|
|
gtk_switch_get_content_size,
|
|
|
|
gtk_switch_allocate_contents,
|
|
|
|
gtk_switch_render_trough,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
priv->slider_gadget = gtk_css_custom_gadget_new ("slider",
|
|
|
|
GTK_WIDGET (self),
|
|
|
|
priv->gadget,
|
|
|
|
NULL,
|
|
|
|
gtk_switch_get_slider_size,
|
|
|
|
NULL,
|
|
|
|
gtk_switch_render_slider,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2015-02-16 22:05:05 +00:00
|
|
|
|
2019-01-24 22:23:40 +00:00
|
|
|
priv->on_gadget = gtk_icon_helper_new_named ("image", GTK_WIDGET (self));
|
|
|
|
_gtk_icon_helper_set_icon_name (GTK_ICON_HELPER (priv->on_gadget), "switch-on-symbolic", GTK_ICON_SIZE_MENU);
|
|
|
|
gtk_css_node_set_parent (gtk_css_gadget_get_node (priv->on_gadget), widget_node);
|
|
|
|
gtk_css_node_set_state (gtk_css_gadget_get_node (priv->on_gadget), gtk_css_node_get_state (widget_node));
|
|
|
|
|
|
|
|
priv->off_gadget = gtk_icon_helper_new_named ("image", GTK_WIDGET (self));
|
|
|
|
_gtk_icon_helper_set_icon_name (GTK_ICON_HELPER (priv->off_gadget), "switch-off-symbolic", GTK_ICON_SIZE_MENU);
|
|
|
|
gtk_css_node_set_parent (gtk_css_gadget_get_node (priv->off_gadget), widget_node);
|
|
|
|
gtk_css_node_set_state (gtk_css_gadget_get_node (priv->off_gadget), gtk_css_node_get_state (widget_node));
|
|
|
|
|
2014-05-19 14:08:56 +00:00
|
|
|
gesture = gtk_gesture_multi_press_new (GTK_WIDGET (self));
|
|
|
|
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE);
|
|
|
|
gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (gesture), TRUE);
|
|
|
|
g_signal_connect (gesture, "pressed",
|
|
|
|
G_CALLBACK (gtk_switch_multipress_gesture_pressed), self);
|
|
|
|
g_signal_connect (gesture, "released",
|
|
|
|
G_CALLBACK (gtk_switch_multipress_gesture_released), self);
|
2014-05-26 12:02:30 +00:00
|
|
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture),
|
2014-05-27 10:38:49 +00:00
|
|
|
GTK_PHASE_BUBBLE);
|
2015-02-16 15:58:17 +00:00
|
|
|
priv->multipress_gesture = gesture;
|
2014-05-19 14:08:56 +00:00
|
|
|
|
|
|
|
gesture = gtk_gesture_pan_new (GTK_WIDGET (self),
|
2014-05-26 10:38:06 +00:00
|
|
|
GTK_ORIENTATION_HORIZONTAL);
|
2014-05-19 14:08:56 +00:00
|
|
|
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE);
|
|
|
|
gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (gesture), TRUE);
|
|
|
|
g_signal_connect (gesture, "pan",
|
|
|
|
G_CALLBACK (gtk_switch_pan_gesture_pan), self);
|
|
|
|
g_signal_connect (gesture, "drag-end",
|
|
|
|
G_CALLBACK (gtk_switch_pan_gesture_drag_end), self);
|
2014-05-26 12:02:30 +00:00
|
|
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture),
|
2014-05-27 10:38:49 +00:00
|
|
|
GTK_PHASE_BUBBLE);
|
2015-02-16 15:58:17 +00:00
|
|
|
priv->pan_gesture = gesture;
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_switch_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkSwitch widget.
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the newly created #GtkSwitch instance
|
2010-11-29 20:49:38 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2010-11-26 13:24:04 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_switch_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_SWITCH, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_switch_set_active:
|
|
|
|
* @sw: a #GtkSwitch
|
|
|
|
* @is_active: %TRUE if @sw should be active, and %FALSE otherwise
|
|
|
|
*
|
|
|
|
* Changes the state of @sw to the desired one.
|
2010-11-29 20:49:38 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2010-11-26 13:24:04 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_switch_set_active (GtkSwitch *sw,
|
|
|
|
gboolean is_active)
|
|
|
|
{
|
|
|
|
GtkSwitchPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SWITCH (sw));
|
|
|
|
|
2014-08-04 12:21:59 +00:00
|
|
|
gtk_switch_end_toggle_animation (sw);
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
is_active = !!is_active;
|
|
|
|
|
|
|
|
priv = sw->priv;
|
|
|
|
|
|
|
|
if (priv->is_active != is_active)
|
|
|
|
{
|
2010-11-29 00:18:56 +00:00
|
|
|
AtkObject *accessible;
|
2014-03-29 17:40:08 +00:00
|
|
|
gboolean handled;
|
2010-11-29 00:18:56 +00:00
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
priv->is_active = is_active;
|
|
|
|
|
2014-08-04 12:30:23 +00:00
|
|
|
if (priv->is_active)
|
2015-02-16 05:25:44 +00:00
|
|
|
priv->handle_pos = 1.0;
|
2014-08-04 12:30:23 +00:00
|
|
|
else
|
2015-02-16 05:25:44 +00:00
|
|
|
priv->handle_pos = 0.0;
|
2014-08-04 12:30:23 +00:00
|
|
|
|
2014-03-29 17:40:08 +00:00
|
|
|
g_signal_emit (sw, signals[STATE_SET], 0, is_active, &handled);
|
2010-11-26 13:24:04 +00:00
|
|
|
|
2015-07-02 01:02:57 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (sw), switch_props[PROP_ACTIVE]);
|
|
|
|
|
2010-11-29 00:18:56 +00:00
|
|
|
accessible = gtk_widget_get_accessible (GTK_WIDGET (sw));
|
|
|
|
atk_object_notify_state_change (accessible, ATK_STATE_CHECKED, priv->is_active);
|
|
|
|
|
2015-03-09 05:16:50 +00:00
|
|
|
gtk_widget_queue_allocate (GTK_WIDGET (sw));
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_switch_get_active:
|
|
|
|
* @sw: a #GtkSwitch
|
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
* Gets whether the #GtkSwitch is in its “on” or “off” state.
|
2010-11-26 13:24:04 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: %TRUE if the #GtkSwitch is active, and %FALSE otherwise
|
2010-11-29 20:49:38 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2010-11-26 13:24:04 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_switch_get_active (GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_SWITCH (sw), FALSE);
|
|
|
|
|
|
|
|
return sw->priv->is_active;
|
|
|
|
}
|
|
|
|
|
2014-03-29 17:40:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_switch_set_state:
|
|
|
|
* @sw: a #GtkSwitch
|
|
|
|
* @state: the new state
|
|
|
|
*
|
|
|
|
* Sets the underlying state of the #GtkSwitch.
|
|
|
|
*
|
|
|
|
* Normally, this is the same as #GtkSwitch:active, unless the switch
|
|
|
|
* is set up for delayed state changes. This function is typically
|
|
|
|
* called from a #GtkSwitch::state-set signal handler.
|
|
|
|
*
|
|
|
|
* See #GtkSwitch::state-set for details.
|
|
|
|
*
|
|
|
|
* Since: 3.14
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_switch_set_state (GtkSwitch *sw,
|
|
|
|
gboolean state)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_SWITCH (sw));
|
|
|
|
|
|
|
|
state = state != FALSE;
|
|
|
|
|
|
|
|
if (sw->priv->state == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sw->priv->state = state;
|
|
|
|
|
|
|
|
/* This will be a no-op if we're switching the state in response
|
|
|
|
* to a UI change. We're setting active anyway, to catch 'spontaneous'
|
|
|
|
* state changes.
|
|
|
|
*/
|
|
|
|
gtk_switch_set_active (sw, state);
|
|
|
|
|
|
|
|
if (state)
|
2016-03-23 17:14:57 +00:00
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (sw), GTK_STATE_FLAG_CHECKED, FALSE);
|
2014-03-29 17:40:08 +00:00
|
|
|
else
|
2016-03-23 17:14:57 +00:00
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (sw), GTK_STATE_FLAG_CHECKED);
|
2014-03-29 17:40:08 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (sw), "state");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_switch_get_state:
|
|
|
|
* @sw: a #GtkSwitch
|
|
|
|
*
|
|
|
|
* Gets the underlying state of the #GtkSwitch.
|
|
|
|
*
|
|
|
|
* Returns: the underlying state
|
|
|
|
*
|
|
|
|
* Since: 3.14
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_switch_get_state (GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_SWITCH (sw), FALSE);
|
|
|
|
|
|
|
|
return sw->priv->state;
|
|
|
|
}
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
static void
|
|
|
|
gtk_switch_update (GtkActivatable *activatable,
|
|
|
|
GtkAction *action,
|
|
|
|
const gchar *property_name)
|
|
|
|
{
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
if (strcmp (property_name, "visible") == 0)
|
|
|
|
{
|
|
|
|
if (gtk_action_is_visible (action))
|
|
|
|
gtk_widget_show (GTK_WIDGET (activatable));
|
|
|
|
else
|
|
|
|
gtk_widget_hide (GTK_WIDGET (activatable));
|
|
|
|
}
|
|
|
|
else if (strcmp (property_name, "sensitive") == 0)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
|
|
|
|
}
|
|
|
|
else if (strcmp (property_name, "active") == 0)
|
|
|
|
{
|
|
|
|
gtk_action_block_activate (action);
|
|
|
|
gtk_switch_set_active (GTK_SWITCH (activatable), gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
|
|
|
|
gtk_action_unblock_activate (action);
|
|
|
|
}
|
2013-06-28 15:27:19 +00:00
|
|
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_sync_action_properties (GtkActivatable *activatable,
|
|
|
|
GtkAction *action)
|
|
|
|
{
|
|
|
|
if (!action)
|
|
|
|
return;
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
2010-11-26 13:24:04 +00:00
|
|
|
if (gtk_action_is_visible (action))
|
|
|
|
gtk_widget_show (GTK_WIDGET (activatable));
|
|
|
|
else
|
|
|
|
gtk_widget_hide (GTK_WIDGET (activatable));
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
|
|
|
|
|
|
|
|
gtk_action_block_activate (action);
|
|
|
|
gtk_switch_set_active (GTK_SWITCH (activatable), gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
|
|
|
|
gtk_action_unblock_activate (action);
|
2013-06-28 15:27:19 +00:00
|
|
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2010-11-26 13:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_switch_activatable_interface_init (GtkActivatableIface *iface)
|
|
|
|
{
|
|
|
|
iface->update = gtk_switch_update;
|
|
|
|
iface->sync_action_properties = gtk_switch_sync_action_properties;
|
|
|
|
}
|