[gtk/wip/baedert/for-master] togglebutton: Modernice source file
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master] togglebutton: Modernice source file
- Date: Sat, 1 Aug 2020 18:01:24 +0000 (UTC)
commit 415946eb0f3b76ba255fb7be5e3177a96edf67e0
Author: Timm Bäder <mail baedert org>
Date: Sat Aug 1 19:24:54 2020 +0200
togglebutton: Modernice source file
Make this a little less ancient looking.
gtk/gtktogglebutton.c | 192 ++++++++++++++++++++++----------------------------
1 file changed, 85 insertions(+), 107 deletions(-)
---
diff --git a/gtk/gtktogglebutton.c b/gtk/gtktogglebutton.c
index 6a31c8f4d9..343efdb593 100644
--- a/gtk/gtktogglebutton.c
+++ b/gtk/gtktogglebutton.c
@@ -115,36 +115,86 @@ enum {
NUM_PROPERTIES
};
+static guint toggle_button_signals[LAST_SIGNAL] = { 0 };
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);
+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);
-static guint toggle_button_signals[LAST_SIGNAL] = { 0 };
+ 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;
+ }
+}
-G_DEFINE_TYPE_WITH_CODE (GtkToggleButton, gtk_toggle_button, GTK_TYPE_BUTTON,
- G_ADD_PRIVATE (GtkToggleButton))
+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_class_init (GtkToggleButtonClass *class)
+gtk_toggle_button_clicked (GtkButton *button)
{
- GObjectClass *gobject_class;
- GtkWidgetClass *widget_class;
- GtkButtonClass *button_class;
+ GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
+ GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
- gobject_class = G_OBJECT_CLASS (class);
- widget_class = (GtkWidgetClass*) class;
- button_class = (GtkButtonClass*) class;
+ 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 = 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;
@@ -173,12 +223,12 @@ gtk_toggle_button_class_init (GtkToggleButtonClass *class)
*/
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,
- NULL,
- G_TYPE_NONE, 0);
+ G_OBJECT_CLASS_TYPE (gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GtkToggleButtonClass, toggled),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 0);
gtk_widget_class_set_css_name (widget_class, I_("button"));
}
@@ -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,54 +282,13 @@ 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,
- "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);
-
- 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;
- }
+ return g_object_new (GTK_TYPE_TOGGLE_BUTTON,
+ "label", label,
+ "use-underline", TRUE,
+ NULL);
}
/**
@@ -295,7 +304,7 @@ gtk_toggle_button_get_property (GObject *object,
*/
void
gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
- gboolean is_active)
+ gboolean is_active)
{
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
@@ -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);
-}
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]