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.
This commit is contained in:
@ -23,6 +23,8 @@
|
|||||||
#include "gtkwidget.h"
|
#include "gtkwidget.h"
|
||||||
#include "gtkwidgetprivate.h"
|
#include "gtkwidgetprivate.h"
|
||||||
#include "gtkdebug.h"
|
#include "gtkdebug.h"
|
||||||
|
#include "gtkmodelbutton.h"
|
||||||
|
#include "gtktypebuiltins.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -66,6 +68,8 @@ struct _GtkActionHelper
|
|||||||
gboolean enabled;
|
gboolean enabled;
|
||||||
gboolean active;
|
gboolean active;
|
||||||
|
|
||||||
|
GtkButtonRole role;
|
||||||
|
|
||||||
gint reporting;
|
gint reporting;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -74,6 +78,7 @@ enum
|
|||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_ENABLED,
|
PROP_ENABLED,
|
||||||
PROP_ACTIVE,
|
PROP_ACTIVE,
|
||||||
|
PROP_ROLE,
|
||||||
N_PROPS
|
N_PROPS
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -107,6 +112,17 @@ gtk_action_helper_report_change (GtkActionHelper *helper,
|
|||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
g_assert_not_reached ();
|
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));
|
GTK_NOTE(ACTIONS, g_message("actionhelper: %s found and enabled", helper->action_name));
|
||||||
|
|
||||||
if (helper->target != NULL && state != NULL)
|
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))
|
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)
|
if (should_emit_signals)
|
||||||
{
|
{
|
||||||
@ -158,6 +183,8 @@ gtk_action_helper_action_added (GtkActionHelper *helper,
|
|||||||
|
|
||||||
if (helper->active)
|
if (helper->active)
|
||||||
gtk_action_helper_report_change (helper, PROP_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);
|
g_value_set_boolean (value, helper->active);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_ROLE:
|
||||||
|
g_value_set_enum (value, helper->role);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
@ -313,6 +344,10 @@ gtk_action_helper_class_init (GtkActionHelperClass *class)
|
|||||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||||
gtk_action_helper_pspecs[PROP_ACTIVE] = g_param_spec_boolean ("active", "active", "active", FALSE,
|
gtk_action_helper_pspecs[PROP_ACTIVE] = g_param_spec_boolean ("active", "active", "active", FALSE,
|
||||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
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);
|
g_object_class_install_properties (class, N_PROPS, gtk_action_helper_pspecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,25 @@ enum
|
|||||||
|
|
||||||
static GParamSpec *properties[LAST_PROPERTY] = { NULL, };
|
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
|
static void
|
||||||
gtk_model_button_set_role (GtkModelButton *button,
|
gtk_model_button_set_role (GtkModelButton *button,
|
||||||
GtkButtonRole role)
|
GtkButtonRole role)
|
||||||
@ -80,7 +99,6 @@ gtk_model_button_set_role (GtkModelButton *button,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
button->role = role;
|
button->role = role;
|
||||||
gtk_widget_queue_draw (GTK_WIDGET (button));
|
|
||||||
|
|
||||||
accessible = gtk_widget_get_accessible (GTK_WIDGET (button));
|
accessible = gtk_widget_get_accessible (GTK_WIDGET (button));
|
||||||
switch (role)
|
switch (role)
|
||||||
@ -102,6 +120,10 @@ gtk_model_button_set_role (GtkModelButton *button,
|
|||||||
}
|
}
|
||||||
|
|
||||||
atk_object_set_role (accessible, a11y_role);
|
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
|
static void
|
||||||
@ -135,25 +157,6 @@ gtk_model_button_set_text (GtkModelButton *button,
|
|||||||
g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_TEXT]);
|
g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_TEXT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
static void
|
||||||
gtk_model_button_set_active (GtkModelButton *button,
|
gtk_model_button_set_active (GtkModelButton *button,
|
||||||
gboolean active)
|
gboolean active)
|
||||||
|
Reference in New Issue
Block a user