[gtk+/popover-menu: 12/18] GtkModelButton: Don't require an explicit role
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/popover-menu: 12/18] GtkModelButton: Don't require an explicit role
- Date: Sun, 26 Oct 2014 23:54:09 +0000 (UTC)
commit 4589aec1aa6719df2ebd3c1efdb10ca8bcbba7ed
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Oct 26 18:13:02 2014 -0400
GtkModelButton: Don't require an explicit role
When we have an action-name, we can deduce the role from the
action that is looked up by the action helper.
gtk/gtkactionhelper.c | 41 ++++++++++++++++++++++++++++++++++++++---
gtk/gtkmodelbutton.c | 43 +++++++++++++++++++++++--------------------
2 files changed, 61 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtkactionhelper.c b/gtk/gtkactionhelper.c
index 6ba5985..a9276d5 100644
--- a/gtk/gtkactionhelper.c
+++ b/gtk/gtkactionhelper.c
@@ -23,6 +23,8 @@
#include "gtkwidget.h"
#include "gtkwidgetprivate.h"
#include "gtkdebug.h"
+#include "gtkmodelbutton.h"
+#include "gtktypebuiltins.h"
#include <string.h>
@@ -66,6 +68,8 @@ struct _GtkActionHelper
gboolean enabled;
gboolean active;
+ GtkButtonRole role;
+
gint reporting;
};
@@ -74,6 +78,7 @@ enum
PROP_0,
PROP_ENABLED,
PROP_ACTIVE,
+ PROP_ROLE,
N_PROPS
};
@@ -107,6 +112,17 @@ gtk_action_helper_report_change (GtkActionHelper *helper,
}
break;
+ case PROP_ROLE:
+ {
+ GParamSpec *pspec;
+
+ pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (helper->widget), "role");
+
+ if (pspec && G_PARAM_SPEC_VALUE_TYPE (pspec) == GTK_TYPE_BUTTON_ROLE)
+ g_object_set (G_OBJECT (helper->widget), "role", helper->role, NULL);
+ }
+ break;
+
default:
g_assert_not_reached ();
}
@@ -146,10 +162,19 @@ gtk_action_helper_action_added (GtkActionHelper *helper,
GTK_NOTE(ACTIONS, g_message("actionhelper: %s found and enabled", helper->action_name));
if (helper->target != NULL && state != NULL)
- helper->active = g_variant_equal (state, helper->target);
-
+ {
+ helper->active = g_variant_equal (state, helper->target);
+ helper->role = GTK_BUTTON_ROLE_RADIO;
+ }
else if (state != NULL && g_variant_is_of_type (state, G_VARIANT_TYPE_BOOLEAN))
- helper->active = g_variant_get_boolean (state);
+ {
+ helper->active = g_variant_get_boolean (state);
+ helper->role = GTK_BUTTON_ROLE_CHECK;
+ }
+ else
+ {
+ helper->role = GTK_BUTTON_ROLE_NORMAL;
+ }
if (should_emit_signals)
{
@@ -158,6 +183,8 @@ gtk_action_helper_action_added (GtkActionHelper *helper,
if (helper->active)
gtk_action_helper_report_change (helper, PROP_ACTIVE);
+
+ gtk_action_helper_report_change (helper, PROP_ROLE);
}
}
@@ -242,6 +269,10 @@ gtk_action_helper_get_property (GObject *object, guint prop_id,
g_value_set_boolean (value, helper->active);
break;
+ case PROP_ROLE:
+ g_value_set_enum (value, helper->role);
+ break;
+
default:
g_assert_not_reached ();
}
@@ -313,6 +344,10 @@ gtk_action_helper_class_init (GtkActionHelperClass *class)
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
gtk_action_helper_pspecs[PROP_ACTIVE] = g_param_spec_boolean ("active", "active", "active", FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ gtk_action_helper_pspecs[PROP_ROLE] = g_param_spec_enum ("role", "role", "role",
+ GTK_TYPE_BUTTON_ROLE,
+ GTK_BUTTON_ROLE_NORMAL,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (class, N_PROPS, gtk_action_helper_pspecs);
}
diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c
index 51fae07..5cb627e 100644
--- a/gtk/gtkmodelbutton.c
+++ b/gtk/gtkmodelbutton.c
@@ -70,6 +70,25 @@ enum
static GParamSpec *properties[LAST_PROPERTY] = { NULL, };
static void
+gtk_model_button_update_state (GtkModelButton *button)
+{
+ GtkStateFlags state;
+
+ if (button->role == GTK_BUTTON_ROLE_NORMAL)
+ return;
+
+ state = gtk_widget_get_state_flags (GTK_WIDGET (button));
+
+ state &= ~GTK_STATE_FLAG_CHECKED;
+
+ if (button->active && !button->menu_name)
+ state |= GTK_STATE_FLAG_CHECKED;
+
+ gtk_widget_set_state_flags (GTK_WIDGET (button), state, TRUE);
+}
+
+
+static void
gtk_model_button_set_role (GtkModelButton *button,
GtkButtonRole role)
{
@@ -80,7 +99,6 @@ gtk_model_button_set_role (GtkModelButton *button,
return;
button->role = role;
- gtk_widget_queue_draw (GTK_WIDGET (button));
accessible = gtk_widget_get_accessible (GTK_WIDGET (button));
switch (role)
@@ -102,6 +120,10 @@ gtk_model_button_set_role (GtkModelButton *button,
}
atk_object_set_role (accessible, a11y_role);
+
+ gtk_model_button_update_state (button);
+ gtk_widget_queue_draw (GTK_WIDGET (button));
+ g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_ROLE]);
}
static void
@@ -136,25 +158,6 @@ gtk_model_button_set_text (GtkModelButton *button,
}
static void
-gtk_model_button_update_state (GtkModelButton *button)
-{
- GtkStateFlags state;
-
- if (button->role == GTK_BUTTON_ROLE_NORMAL)
- return;
-
- state = gtk_widget_get_state_flags (GTK_WIDGET (button));
-
- state &= ~GTK_STATE_FLAG_CHECKED;
-
- if (button->active && !button->menu_name)
- state |= GTK_STATE_FLAG_CHECKED;
-
- gtk_widget_set_state_flags (GTK_WIDGET (button), state, TRUE);
-}
-
-
-static void
gtk_model_button_set_active (GtkModelButton *button,
gboolean active)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]