togglebutton: Modernice source file

Make this a little less ancient looking.
This commit is contained in:
Timm Bäder
2020-08-01 19:24:54 +02:00
parent 65b79d2585
commit 415946eb0f

View File

@@ -115,36 +115,86 @@ enum {
NUM_PROPERTIES 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 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_DEFINE_TYPE_WITH_CODE (GtkToggleButton, gtk_toggle_button, GTK_TYPE_BUTTON,
G_ADD_PRIVATE (GtkToggleButton)) 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 static void
gtk_toggle_button_class_init (GtkToggleButtonClass *class) gtk_toggle_button_class_init (GtkToggleButtonClass *class)
{ {
GObjectClass *gobject_class; GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class; GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkButtonClass *button_class; GtkButtonClass *button_class = GTK_BUTTON_CLASS (class);
gobject_class = G_OBJECT_CLASS (class);
widget_class = (GtkWidgetClass*) class;
button_class = (GtkButtonClass*) class;
gobject_class->set_property = gtk_toggle_button_set_property; gobject_class->set_property = gtk_toggle_button_set_property;
gobject_class->get_property = gtk_toggle_button_get_property; gobject_class->get_property = gtk_toggle_button_get_property;
@@ -241,47 +291,6 @@ gtk_toggle_button_new_with_mnemonic (const char *label)
NULL); 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: * gtk_toggle_button_set_active:
* @toggle_button: a #GtkToggleButton. * @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); 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);
}