mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-14 20:51:07 +00:00
togglebutton: Modernice source file
Make this a little less ancient looking.
This commit is contained in:
parent
65b79d2585
commit
415946eb0f
@ -115,36 +115,86 @@ enum {
|
||||
NUM_PROPERTIES
|
||||
};
|
||||
|
||||
static GParamSpec *toggle_button_props[NUM_PROPERTIES] = { NULL, };
|
||||
|
||||
static gboolean gtk_toggle_button_mnemonic_activate (GtkWidget *widget,
|
||||
gboolean group_cycling);
|
||||
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 guint toggle_button_signals[LAST_SIGNAL] = { 0 };
|
||||
static GParamSpec *toggle_button_props[NUM_PROPERTIES] = { NULL, };
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkToggleButton, gtk_toggle_button, GTK_TYPE_BUTTON,
|
||||
G_ADD_PRIVATE (GtkToggleButton))
|
||||
|
||||
static void
|
||||
gtk_toggle_button_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ACTIVE:
|
||||
gtk_toggle_button_set_active (tb, g_value_get_boolean (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_toggle_button_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object);
|
||||
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (tb);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_boolean (value, priv->active);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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_clicked (GtkButton *button)
|
||||
{
|
||||
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
|
||||
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
|
||||
|
||||
gtk_toggle_button_set_active (toggle_button, !priv->active);
|
||||
|
||||
GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked (button);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_toggle_button_class_init (GtkToggleButtonClass *class)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GtkWidgetClass *widget_class;
|
||||
GtkButtonClass *button_class;
|
||||
|
||||
gobject_class = G_OBJECT_CLASS (class);
|
||||
widget_class = (GtkWidgetClass*) class;
|
||||
button_class = (GtkButtonClass*) class;
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
||||
GtkButtonClass *button_class = GTK_BUTTON_CLASS (class);
|
||||
|
||||
gobject_class->set_property = gtk_toggle_button_set_property;
|
||||
gobject_class->get_property = gtk_toggle_button_get_property;
|
||||
@ -201,7 +251,7 @@ gtk_toggle_button_init (GtkToggleButton *toggle_button)
|
||||
*
|
||||
* Returns: a new toggle button.
|
||||
*/
|
||||
GtkWidget*
|
||||
GtkWidget *
|
||||
gtk_toggle_button_new (void)
|
||||
{
|
||||
return g_object_new (GTK_TYPE_TOGGLE_BUTTON, NULL);
|
||||
@ -215,7 +265,7 @@ gtk_toggle_button_new (void)
|
||||
*
|
||||
* Returns: a new toggle button.
|
||||
*/
|
||||
GtkWidget*
|
||||
GtkWidget *
|
||||
gtk_toggle_button_new_with_label (const char *label)
|
||||
{
|
||||
return g_object_new (GTK_TYPE_TOGGLE_BUTTON, "label", label, NULL);
|
||||
@ -232,7 +282,7 @@ gtk_toggle_button_new_with_label (const char *label)
|
||||
*
|
||||
* Returns: a new #GtkToggleButton
|
||||
*/
|
||||
GtkWidget*
|
||||
GtkWidget *
|
||||
gtk_toggle_button_new_with_mnemonic (const char *label)
|
||||
{
|
||||
return g_object_new (GTK_TYPE_TOGGLE_BUTTON,
|
||||
@ -241,47 +291,6 @@ gtk_toggle_button_new_with_mnemonic (const char *label)
|
||||
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);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ACTIVE:
|
||||
gtk_toggle_button_set_active (tb, g_value_get_boolean (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_toggle_button_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object);
|
||||
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (tb);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_boolean (value, priv->active);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_toggle_button_set_active:
|
||||
* @toggle_button: a #GtkToggleButton.
|
||||
@ -356,34 +365,3 @@ gtk_toggle_button_toggled (GtkToggleButton *toggle_button)
|
||||
|
||||
g_signal_emit (toggle_button, toggle_button_signals[TOGGLED], 0);
|
||||
}
|
||||
|
||||
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_clicked (GtkButton *button)
|
||||
{
|
||||
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
|
||||
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
|
||||
|
||||
gtk_toggle_button_set_active (toggle_button, !priv->active);
|
||||
|
||||
if (GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked)
|
||||
GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked (button);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user