* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * 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
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include "config.h"
+
+#include "gtktogglebutton.h"
+
+#include "gtkbuttonprivate.h"
#include "gtklabel.h"
#include "gtkmain.h"
-#include "gtksignal.h"
-#include "gtktogglebutton.h"
+#include "gtkmarshalers.h"
+#include "gtktoggleaction.h"
+#include "gtkactivatable.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
#define DEFAULT_LEFT_POS 4
#define DEFAULT_TOP_POS 4
#define DEFAULT_SPACING 7
+struct _GtkToggleButtonPrivate
+{
+ guint active : 1;
+ guint draw_indicator : 1;
+ guint inconsistent : 1;
+};
+
enum {
TOGGLED,
LAST_SIGNAL
};
+enum {
+ PROP_0,
+ PROP_ACTIVE,
+ PROP_INCONSISTENT,
+ PROP_DRAW_INDICATOR
+};
-static void gtk_toggle_button_class_init (GtkToggleButtonClass *klass);
-static void gtk_toggle_button_init (GtkToggleButton *toggle_button);
-static void gtk_toggle_button_draw_focus (GtkWidget *widget);
-static void gtk_toggle_button_pressed (GtkButton *button);
-static void gtk_toggle_button_released (GtkButton *button);
-static void gtk_toggle_button_clicked (GtkButton *button);
-static void gtk_toggle_button_enter (GtkButton *button);
-static void gtk_toggle_button_leave (GtkButton *button);
-
-
-static guint toggle_button_signals[LAST_SIGNAL] = { 0 };
-
-
-guint
-gtk_toggle_button_get_type (void)
-{
- static guint toggle_button_type = 0;
-
- if (!toggle_button_type)
- {
- GtkTypeInfo toggle_button_info =
- {
- "GtkToggleButton",
- sizeof (GtkToggleButton),
- sizeof (GtkToggleButtonClass),
- (GtkClassInitFunc) gtk_toggle_button_class_init,
- (GtkObjectInitFunc) gtk_toggle_button_init,
- (GtkArgSetFunc) NULL,
- (GtkArgGetFunc) NULL,
- };
-
- toggle_button_type = gtk_type_unique (gtk_button_get_type (), &toggle_button_info);
- }
- return toggle_button_type;
-}
+static gint gtk_toggle_button_draw (GtkWidget *widget,
+ cairo_t *cr);
+static gboolean gtk_toggle_button_mnemonic_activate (GtkWidget *widget,
+ gboolean group_cycling);
+static void gtk_toggle_button_pressed (GtkButton *button);
+static void gtk_toggle_button_released (GtkButton *button);
+static void gtk_toggle_button_clicked (GtkButton *button);
+static void gtk_toggle_button_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_toggle_button_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gtk_toggle_button_update_state (GtkButton *button);
+
+
+static void gtk_toggle_button_activatable_interface_init (GtkActivatableIface *iface);
+static void gtk_toggle_button_update (GtkActivatable *activatable,
+ GtkAction *action,
+ const gchar *property_name);
+static void gtk_toggle_button_sync_action_properties (GtkActivatable *activatable,
+ GtkAction *action);
+
+static GtkActivatableIface *parent_activatable_iface;
+static guint toggle_button_signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE_WITH_CODE (GtkToggleButton, gtk_toggle_button, GTK_TYPE_BUTTON,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
+ gtk_toggle_button_activatable_interface_init))
static void
gtk_toggle_button_class_init (GtkToggleButtonClass *class)
{
- GtkObjectClass *object_class;
+ GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
- GtkContainerClass *container_class;
GtkButtonClass *button_class;
- object_class = (GtkObjectClass*) class;
+ gobject_class = G_OBJECT_CLASS (class);
widget_class = (GtkWidgetClass*) class;
- container_class = (GtkContainerClass*) class;
button_class = (GtkButtonClass*) class;
- toggle_button_signals[TOGGLED] =
- gtk_signal_new ("toggled",
- GTK_RUN_FIRST,
- object_class->type,
- GTK_SIGNAL_OFFSET (GtkToggleButtonClass, toggled),
- gtk_signal_default_marshaller,
- GTK_TYPE_NONE, 0);
+ gobject_class->set_property = gtk_toggle_button_set_property;
+ gobject_class->get_property = gtk_toggle_button_get_property;
- gtk_object_class_add_signals (object_class, toggle_button_signals, LAST_SIGNAL);
-
- widget_class->draw_focus = gtk_toggle_button_draw_focus;
+ widget_class->draw = gtk_toggle_button_draw;
+ widget_class->mnemonic_activate = gtk_toggle_button_mnemonic_activate;
button_class->pressed = gtk_toggle_button_pressed;
button_class->released = gtk_toggle_button_released;
button_class->clicked = gtk_toggle_button_clicked;
- button_class->enter = gtk_toggle_button_enter;
- button_class->leave = gtk_toggle_button_leave;
+ button_class->enter = gtk_toggle_button_update_state;
+ button_class->leave = gtk_toggle_button_update_state;
class->toggled = NULL;
+
+ g_object_class_install_property (gobject_class,
+ PROP_ACTIVE,
+ g_param_spec_boolean ("active",
+ P_("Active"),
+ P_("If the toggle button should be pressed in"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_INCONSISTENT,
+ g_param_spec_boolean ("inconsistent",
+ P_("Inconsistent"),
+ P_("If the toggle button is in an \"in between\" state"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_DRAW_INDICATOR,
+ g_param_spec_boolean ("draw-indicator",
+ P_("Draw Indicator"),
+ P_("If the toggle part of the button is displayed"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ toggle_button_signals[TOGGLED] =
+ g_signal_new (I_("toggled"),
+ G_OBJECT_CLASS_TYPE (gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GtkToggleButtonClass, toggled),
+ NULL, NULL,
+ _gtk_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_type_class_add_private (class, sizeof (GtkToggleButtonPrivate));
}
static void
gtk_toggle_button_init (GtkToggleButton *toggle_button)
{
- toggle_button->active = FALSE;
- toggle_button->draw_indicator = FALSE;
+ GtkToggleButtonPrivate *priv;
+
+ toggle_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (toggle_button,
+ GTK_TYPE_TOGGLE_BUTTON,
+ GtkToggleButtonPrivate);
+ priv = toggle_button->priv;
+
+ priv->active = FALSE;
+ priv->draw_indicator = FALSE;
+ GTK_BUTTON (toggle_button)->priv->depress_on_activate = TRUE;
+}
+
+static void
+gtk_toggle_button_activatable_interface_init (GtkActivatableIface *iface)
+{
+ parent_activatable_iface = g_type_interface_peek_parent (iface);
+ iface->update = gtk_toggle_button_update;
+ iface->sync_action_properties = gtk_toggle_button_sync_action_properties;
+}
+
+static void
+gtk_toggle_button_update (GtkActivatable *activatable,
+ GtkAction *action,
+ const gchar *property_name)
+{
+ GtkToggleButton *button;
+
+ parent_activatable_iface->update (activatable, action, property_name);
+
+ button = GTK_TOGGLE_BUTTON (activatable);
+
+ if (strcmp (property_name, "active") == 0)
+ {
+ gtk_action_block_activate (action);
+ gtk_toggle_button_set_active (button, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+ gtk_action_unblock_activate (action);
+ }
+
+}
+
+static void
+gtk_toggle_button_sync_action_properties (GtkActivatable *activatable,
+ GtkAction *action)
+{
+ GtkToggleButton *button;
+
+ parent_activatable_iface->sync_action_properties (activatable, action);
+
+ if (!GTK_IS_TOGGLE_ACTION (action))
+ return;
+
+ button = GTK_TOGGLE_BUTTON (activatable);
+
+ gtk_action_block_activate (action);
+ gtk_toggle_button_set_active (button, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+ gtk_action_unblock_activate (action);
}
GtkWidget*
gtk_toggle_button_new (void)
{
- return GTK_WIDGET (gtk_type_new (gtk_toggle_button_get_type ()));
+ return g_object_new (GTK_TYPE_TOGGLE_BUTTON, NULL);
}
GtkWidget*
gtk_toggle_button_new_with_label (const gchar *label)
{
- GtkWidget *toggle_button;
- GtkWidget *label_widget;
+ return g_object_new (GTK_TYPE_TOGGLE_BUTTON, "label", label, NULL);
+}
+
+/**
+ * gtk_toggle_button_new_with_mnemonic:
+ * @label: the text of the button, with an underscore in front of the
+ * mnemonic character
+ * @returns: a new #GtkToggleButton
+ *
+ * Creates a new #GtkToggleButton containing a label. The label
+ * will be created using gtk_label_new_with_mnemonic(), so underscores
+ * in @label indicate the mnemonic for the button.
+ **/
+GtkWidget*
+gtk_toggle_button_new_with_mnemonic (const gchar *label)
+{
+ return g_object_new (GTK_TYPE_TOGGLE_BUTTON,
+ "label", label,
+ "use-underline", TRUE,
+ NULL);
+}
+
+static void
+gtk_toggle_button_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkToggleButton *tb;
+
+ tb = GTK_TOGGLE_BUTTON (object);
- toggle_button = gtk_toggle_button_new ();
- label_widget = gtk_label_new (label);
- gtk_misc_set_alignment (GTK_MISC (label_widget), 0.5, 0.5);
+ switch (prop_id)
+ {
+ case PROP_ACTIVE:
+ gtk_toggle_button_set_active (tb, g_value_get_boolean (value));
+ break;
+ case PROP_INCONSISTENT:
+ gtk_toggle_button_set_inconsistent (tb, g_value_get_boolean (value));
+ break;
+ case PROP_DRAW_INDICATOR:
+ gtk_toggle_button_set_mode (tb, g_value_get_boolean (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
- gtk_container_add (GTK_CONTAINER (toggle_button), label_widget);
- gtk_widget_show (label_widget);
+static void
+gtk_toggle_button_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object);
+ GtkToggleButtonPrivate *priv = tb->priv;
- return toggle_button;
+ switch (prop_id)
+ {
+ case PROP_ACTIVE:
+ g_value_set_boolean (value, priv->active);
+ break;
+ case PROP_INCONSISTENT:
+ g_value_set_boolean (value, priv->inconsistent);
+ break;
+ case PROP_DRAW_INDICATOR:
+ g_value_set_boolean (value, priv->draw_indicator);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
+/**
+ * gtk_toggle_button_set_mode:
+ * @toggle_button: a #GtkToggleButton
+ * @draw_indicator: if %TRUE, draw the button as a separate indicator
+ * and label; if %FALSE, draw the button like a normal button
+ *
+ * Sets whether the button is displayed as a separate indicator and label.
+ * You can call this function on a checkbutton or a radiobutton with
+ * @draw_indicator = %FALSE to make the button look like a normal button
+ *
+ * This function only affects instances of classes like #GtkCheckButton
+ * and #GtkRadioButton that derive from #GtkToggleButton,
+ * not instances of #GtkToggleButton itself.
+ */
void
gtk_toggle_button_set_mode (GtkToggleButton *toggle_button,
- gint draw_indicator)
+ gboolean draw_indicator)
{
- g_return_if_fail (toggle_button != NULL);
+ GtkToggleButtonPrivate *priv;
+
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
+ priv = toggle_button->priv;
+
draw_indicator = draw_indicator ? TRUE : FALSE;
- if (toggle_button->draw_indicator != draw_indicator)
+ if (priv->draw_indicator != draw_indicator)
{
- toggle_button->draw_indicator = draw_indicator;
+ GtkStyleContext *context;
- if (GTK_WIDGET_VISIBLE (toggle_button))
+ priv->draw_indicator = draw_indicator;
+ GTK_BUTTON (toggle_button)->priv->depress_on_activate = !draw_indicator;
+
+ if (gtk_widget_get_visible (GTK_WIDGET (toggle_button)))
gtk_widget_queue_resize (GTK_WIDGET (toggle_button));
+
+ g_object_notify (G_OBJECT (toggle_button), "draw-indicator");
+
+ /* Make toggle buttons conditionally have the "button"
+ * class depending on draw_indicator.
+ */
+ context = gtk_widget_get_style_context (GTK_WIDGET (toggle_button));
+
+ if (draw_indicator)
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BUTTON);
+ else
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
}
}
-void
-gtk_toggle_button_set_state (GtkToggleButton *toggle_button,
- gint state)
+/**
+ * gtk_toggle_button_get_mode:
+ * @toggle_button: a #GtkToggleButton
+ *
+ * Retrieves whether the button is displayed as a separate indicator
+ * and label. See gtk_toggle_button_set_mode().
+ *
+ * Return value: %TRUE if the togglebutton is drawn as a separate indicator
+ * and label.
+ **/
+gboolean
+gtk_toggle_button_get_mode (GtkToggleButton *toggle_button)
{
- g_return_if_fail (toggle_button != NULL);
- g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
+ g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE);
- if (toggle_button->active != (state != FALSE))
- gtk_button_clicked (GTK_BUTTON (toggle_button));
+ return toggle_button->priv->draw_indicator;
}
void
-gtk_toggle_button_toggled (GtkToggleButton *toggle_button)
+gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
+ gboolean is_active)
{
- gtk_signal_emit (GTK_OBJECT (toggle_button), toggle_button_signals[TOGGLED]);
-}
+ GtkToggleButtonPrivate *priv;
+ g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
-static void
-gtk_toggle_button_draw_focus (GtkWidget *widget)
-{
- GtkButton *button;
- GtkToggleButton *toggle_button;
- GtkShadowType shadow_type;
- gint width, height;
- gint x, y;
+ priv = toggle_button->priv;
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget));
+ is_active = is_active != FALSE;
- if (GTK_WIDGET_DRAWABLE (widget))
- {
- button = GTK_BUTTON (widget);
- toggle_button = GTK_TOGGLE_BUTTON (widget);
-
- x = 0;
- y = 0;
- width = widget->allocation.width - GTK_CONTAINER (widget)->border_width * 2;
- height = widget->allocation.height - GTK_CONTAINER (widget)->border_width * 2;
-
- if (GTK_WIDGET_CAN_DEFAULT (widget))
- {
- x += widget->style->klass->xthickness;
- y += widget->style->klass->ythickness;
- width -= 2 * x + DEFAULT_SPACING;
- height -= 2 * y + DEFAULT_SPACING;
- x += DEFAULT_LEFT_POS;
- y += DEFAULT_TOP_POS;
- }
-
- if (GTK_WIDGET_HAS_FOCUS (widget))
- {
- x += 1;
- y += 1;
- width -= 2;
- height -= 2;
- }
- else
- {
- if (GTK_WIDGET_STATE (toggle_button) == GTK_STATE_ACTIVE)
- gdk_draw_rectangle (widget->window,
- widget->style->bg_gc[GTK_WIDGET_STATE (widget)], FALSE,
- x + 1, y + 1, width - 4, height - 4);
- else
- gdk_draw_rectangle (widget->window,
- widget->style->bg_gc[GTK_WIDGET_STATE (widget)], FALSE,
- x + 2, y + 2, width - 5, height - 5);
- }
-
- if (toggle_button->active)
- shadow_type = GTK_SHADOW_IN;
- else
- shadow_type = GTK_SHADOW_OUT;
-
- gtk_draw_shadow (widget->style, widget->window,
- GTK_WIDGET_STATE (widget), shadow_type,
- x, y, width, height);
-
- if (GTK_WIDGET_HAS_FOCUS (widget))
- {
- x -= 1;
- y -= 1;
- width += 2;
- height += 2;
-
- gdk_draw_rectangle (widget->window,
- widget->style->black_gc, FALSE,
- x, y, width - 1, height - 1);
- }
- }
+ if (priv->active != is_active)
+ gtk_button_clicked (GTK_BUTTON (toggle_button));
}
-static void
-gtk_toggle_button_pressed (GtkButton *button)
+void
+_gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
+ gboolean is_active)
{
- GtkToggleButton *toggle_button;
- GtkStateType new_state;
+ toggle_button->priv->active = is_active;
+}
- g_return_if_fail (button != NULL);
- g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
+gboolean
+gtk_toggle_button_get_active (GtkToggleButton *toggle_button)
+{
+ g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE);
- toggle_button = GTK_TOGGLE_BUTTON (button);
+ return toggle_button->priv->active;
+}
- button->button_down = TRUE;
- if (toggle_button->active)
- new_state = (button->in_button ? GTK_STATE_NORMAL : GTK_STATE_ACTIVE);
- else
- new_state = (button->in_button ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL);
+void
+gtk_toggle_button_toggled (GtkToggleButton *toggle_button)
+{
+ g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
- if (GTK_WIDGET_STATE (button) != new_state)
- {
- gtk_widget_set_state (GTK_WIDGET (button), new_state);
- gtk_widget_queue_draw (GTK_WIDGET (button));
- }
+ g_signal_emit (toggle_button, toggle_button_signals[TOGGLED], 0);
}
-static void
-gtk_toggle_button_released (GtkButton *button)
+/**
+ * gtk_toggle_button_set_inconsistent:
+ * @toggle_button: a #GtkToggleButton
+ * @setting: %TRUE if state is inconsistent
+ *
+ * If the user has selected a range of elements (such as some text or
+ * spreadsheet cells) that are affected by a toggle button, and the
+ * current values in that range are inconsistent, you may want to
+ * display the toggle in an "in between" state. This function turns on
+ * "in between" display. Normally you would turn off the inconsistent
+ * state again if the user toggles the toggle button. This has to be
+ * done manually, gtk_toggle_button_set_inconsistent() only affects
+ * visual appearance, it doesn't affect the semantics of the button.
+ *
+ **/
+void
+gtk_toggle_button_set_inconsistent (GtkToggleButton *toggle_button,
+ gboolean setting)
{
- GtkToggleButton *toggle_button;
- GtkStateType new_state;
+ GtkToggleButtonPrivate *priv;
+
+ g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
+
+ priv = toggle_button->priv;
- g_return_if_fail (button != NULL);
- g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
+ setting = setting != FALSE;
- if (button->button_down)
+ if (setting != priv->inconsistent)
{
- toggle_button = GTK_TOGGLE_BUTTON (button);
+ priv->inconsistent = setting;
- button->button_down = FALSE;
+ gtk_toggle_button_update_state (GTK_BUTTON (toggle_button));
+ gtk_widget_queue_draw (GTK_WIDGET (toggle_button));
- if (button->in_button)
- {
- gtk_button_clicked (button);
- }
- else
- {
- if (toggle_button->active)
- new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);
- else
- new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL);
-
- if (GTK_WIDGET_STATE (button) != new_state)
- {
- gtk_widget_set_state (GTK_WIDGET (button), new_state);
- gtk_widget_queue_draw (GTK_WIDGET (button));
- }
- }
+ g_object_notify (G_OBJECT (toggle_button), "inconsistent");
}
}
-static void
-gtk_toggle_button_clicked (GtkButton *button)
+/**
+ * gtk_toggle_button_get_inconsistent:
+ * @toggle_button: a #GtkToggleButton
+ *
+ * Gets the value set by gtk_toggle_button_set_inconsistent().
+ *
+ * Return value: %TRUE if the button is displayed as inconsistent, %FALSE otherwise
+ **/
+gboolean
+gtk_toggle_button_get_inconsistent (GtkToggleButton *toggle_button)
{
- GtkToggleButton *toggle_button;
- GtkStateType new_state;
+ g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE);
- g_return_if_fail (button != NULL);
- g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
+ return toggle_button->priv->inconsistent;
+}
- toggle_button = GTK_TOGGLE_BUTTON (button);
- toggle_button->active = !toggle_button->active;
+static gint
+gtk_toggle_button_draw (GtkWidget *widget,
+ cairo_t *cr)
+{
+ GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (widget);
+ GtkToggleButtonPrivate *priv = toggle_button->priv;
+ GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
+ GtkButton *button = GTK_BUTTON (widget);
+ GtkStateType state_type;
+ GtkShadowType shadow_type;
- gtk_toggle_button_toggled (toggle_button);
+ state_type = gtk_widget_get_state (widget);
- if (toggle_button->active)
- new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);
+ if (priv->inconsistent)
+ {
+ if (state_type == GTK_STATE_ACTIVE)
+ state_type = GTK_STATE_NORMAL;
+ shadow_type = GTK_SHADOW_ETCHED_IN;
+ }
else
- new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL);
+ shadow_type = button->priv->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
- if (GTK_WIDGET_STATE (button) != new_state)
- gtk_widget_set_state (GTK_WIDGET (button), new_state);
- gtk_widget_queue_draw (GTK_WIDGET (button));
+ _gtk_button_paint (button, cr,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget),
+ state_type, shadow_type,
+ "togglebutton", "togglebuttondefault");
+
+ if (child)
+ gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr);
+
+ return FALSE;
+}
+
+static gboolean
+gtk_toggle_button_mnemonic_activate (GtkWidget *widget,
+ gboolean group_cycling)
+{
+ /*
+ * We override the standard implementation in
+ * gtk_widget_real_mnemonic_activate() in order to focus the widget even
+ * if there is no mnemonic conflict.
+ */
+ if (gtk_widget_get_can_focus (widget))
+ gtk_widget_grab_focus (widget);
+
+ if (!group_cycling)
+ gtk_widget_activate (widget);
+
+ return TRUE;
}
static void
-gtk_toggle_button_enter (GtkButton *button)
+gtk_toggle_button_pressed (GtkButton *button)
{
- GtkToggleButton *toggle_button;
- GtkStateType new_state;
+ button->priv->button_down = TRUE;
- g_return_if_fail (button != NULL);
- g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
+ gtk_toggle_button_update_state (button);
+ gtk_widget_queue_draw (GTK_WIDGET (button));
+}
- toggle_button = GTK_TOGGLE_BUTTON (button);
+static void
+gtk_toggle_button_released (GtkButton *button)
+{
+ if (button->priv->button_down)
+ {
+ button->priv->button_down = FALSE;
- if (toggle_button->active)
- new_state = (button->button_down ? GTK_STATE_NORMAL : GTK_STATE_PRELIGHT);
- else
- new_state = (button->button_down ? GTK_STATE_ACTIVE : GTK_STATE_PRELIGHT);
+ if (button->priv->in_button)
+ gtk_button_clicked (button);
- if (GTK_WIDGET_STATE (button) != new_state)
- {
- gtk_widget_set_state (GTK_WIDGET (button), new_state);
+ gtk_toggle_button_update_state (button);
gtk_widget_queue_draw (GTK_WIDGET (button));
}
}
static void
-gtk_toggle_button_leave (GtkButton *button)
+gtk_toggle_button_clicked (GtkButton *button)
{
- GtkToggleButton *toggle_button;
- GtkStateType new_state;
+ GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
+ GtkToggleButtonPrivate *priv = toggle_button->priv;
- g_return_if_fail (button != NULL);
- g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
+ priv->active = !priv->active;
- toggle_button = GTK_TOGGLE_BUTTON (button);
+ gtk_toggle_button_toggled (toggle_button);
- new_state = (toggle_button->active ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL);
+ gtk_toggle_button_update_state (button);
- if (GTK_WIDGET_STATE (button) != new_state)
- {
- gtk_widget_set_state (GTK_WIDGET (button), new_state);
- gtk_widget_queue_draw (GTK_WIDGET (button));
- }
+ g_object_notify (G_OBJECT (toggle_button), "active");
+
+ if (GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked)
+ GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked (button);
+}
+
+static void
+gtk_toggle_button_update_state (GtkButton *button)
+{
+ GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
+ GtkToggleButtonPrivate *priv = toggle_button->priv;
+ gboolean depressed, touchscreen;
+ GtkStateFlags new_state = 0;
+
+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (button)),
+ "gtk-touchscreen-mode", &touchscreen,
+ NULL);
+
+ if (priv->inconsistent)
+ new_state |= GTK_STATE_FLAG_INCONSISTENT;
+
+ if (priv->inconsistent)
+ depressed = FALSE;
+ else if (button->priv->in_button && button->priv->button_down)
+ depressed = TRUE;
+ else
+ depressed = priv->active;
+
+ if (!touchscreen && button->priv->in_button && (!button->priv->button_down || priv->draw_indicator))
+ new_state |= GTK_STATE_FLAG_PRELIGHT;
+
+ if (depressed)
+ new_state |= GTK_STATE_FLAG_ACTIVE;
+
+ _gtk_button_set_depressed (button, depressed);
+ gtk_widget_set_state_flags (GTK_WIDGET (toggle_button), new_state, TRUE);
}