i Bug 560228 – Add "action-controller" property to GtkWidgetClass
Rework the way actions and proxies interact, to make the
interaction less ad hoc, more extensible, and better suited
for support in GUI builders like glade.
To be used as a proxy, a widget must now implement the
GtkActivatable interface, and GtkActivatable implementations
are responsible for syncing their appearance with the action
and for activating the action.
All the widgets that are commonly used as proxies implement
GtkActivatable now.
Patch by Tristan van Berkom.
* gtk/gtkactivatable.[hc]: The GtkActivatable interface.
* gtk/gtkbutton.c:
* gtk/gtktogglebutton.c:
* gtk/gtktoolitem.c:
* gtk/gtktoolbutton.c:
* gtk/gtktoggletoolbutton.c:
* gtk/gtkmenuitem.c:
* gtk/gtkcheckmenuitem.c:
* gtk/gtkimagemenuitem.c:
* gtk/gtkradiomenuitem.c:
* gtk/gtkrecentchooserprivate.h:
* gtk/gtkrecentchooser.c:
* gtk/gtkrecentchooserdefault.c:
* gtk/gtkrecentchoosermenu.c: Implement GtkActivatable.
* gtk/gtkaction.[hc]: Move appearance synchronization to
GtkActivatable implementations.
* gtk/gtkradioaction.c:
* gtk/gtkrecentaction.c:
* gtk/gtktoggleaction.c:
* gtk/gtkactiongroup.c: Adapt.
* gtk/gtk.h: Include gtkactivatable.h
* gtk/gtk.symbols: Add new functions
svn path=/trunk/; revision=22195
This commit is contained in:
@ -27,6 +27,8 @@
|
||||
#include "config.h"
|
||||
#include "gtkcheckmenuitem.h"
|
||||
#include "gtkaccellabel.h"
|
||||
#include "gtkactivatable.h"
|
||||
#include "gtktoggleaction.h"
|
||||
#include "gtkmarshalers.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkintl.h"
|
||||
@ -53,19 +55,28 @@ static void gtk_check_menu_item_draw_indicator (GtkCheckMenuItem *che
|
||||
GdkRectangle *area);
|
||||
static void gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item,
|
||||
GdkRectangle *area);
|
||||
static void gtk_check_menu_item_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gtk_check_menu_item_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gtk_check_menu_item_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gtk_check_menu_item_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static void gtk_check_menu_item_activatable_interface_init (GtkActivatableIface *iface);
|
||||
static void gtk_check_menu_item_activatable_update (GtkActivatable *activatable,
|
||||
GtkAction *action,
|
||||
const gchar *property_name);
|
||||
static void gtk_check_menu_item_activatable_reset (GtkActivatable *activatable,
|
||||
GtkAction *action);
|
||||
|
||||
static guint check_menu_item_signals[LAST_SIGNAL] = { 0 };
|
||||
static GtkActivatableIface *parent_activatable_iface;
|
||||
static guint check_menu_item_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
G_DEFINE_TYPE (GtkCheckMenuItem, gtk_check_menu_item, GTK_TYPE_MENU_ITEM)
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkCheckMenuItem, gtk_check_menu_item, GTK_TYPE_MENU_ITEM,
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
|
||||
gtk_check_menu_item_activatable_interface_init))
|
||||
|
||||
static void
|
||||
gtk_check_menu_item_class_init (GtkCheckMenuItemClass *klass)
|
||||
@ -107,8 +118,7 @@ gtk_check_menu_item_class_init (GtkCheckMenuItemClass *klass)
|
||||
|
||||
gtk_widget_class_install_style_property (widget_class,
|
||||
g_param_spec_int ("indicator-size",
|
||||
P_("Indicator Size")
|
||||
,
|
||||
P_("Indicator Size"),
|
||||
P_("Size of check or radio indicator"),
|
||||
0,
|
||||
G_MAXINT,
|
||||
@ -134,6 +144,64 @@ gtk_check_menu_item_class_init (GtkCheckMenuItemClass *klass)
|
||||
G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_check_menu_item_activatable_interface_init (GtkActivatableIface *iface)
|
||||
{
|
||||
parent_activatable_iface = g_type_interface_peek_parent (iface);
|
||||
iface->update = gtk_check_menu_item_activatable_update;
|
||||
iface->reset = gtk_check_menu_item_activatable_reset;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_check_menu_item_activatable_update (GtkActivatable *activatable,
|
||||
GtkAction *action,
|
||||
const gchar *property_name)
|
||||
{
|
||||
GtkCheckMenuItem *check_menu_item;
|
||||
|
||||
check_menu_item = GTK_CHECK_MENU_ITEM (activatable);
|
||||
|
||||
parent_activatable_iface->update (activatable, action, property_name);
|
||||
|
||||
if (strcmp (property_name, "active") == 0)
|
||||
{
|
||||
gtk_action_block_activate (action);
|
||||
gtk_check_menu_item_set_active (check_menu_item, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
|
||||
gtk_action_unblock_activate (action);
|
||||
}
|
||||
|
||||
if (!gtk_activatable_get_use_action_appearance (activatable))
|
||||
return;
|
||||
|
||||
if (strcmp (property_name, "draw-as-radio") == 0)
|
||||
gtk_check_menu_item_set_draw_as_radio (check_menu_item,
|
||||
gtk_toggle_action_get_draw_as_radio (GTK_TOGGLE_ACTION (action)));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_check_menu_item_activatable_reset (GtkActivatable *activatable,
|
||||
GtkAction *action)
|
||||
{
|
||||
GtkCheckMenuItem *check_menu_item;
|
||||
|
||||
check_menu_item = GTK_CHECK_MENU_ITEM (activatable);
|
||||
|
||||
parent_activatable_iface->reset (activatable, action);
|
||||
|
||||
if (!action)
|
||||
return;
|
||||
|
||||
gtk_action_block_activate (action);
|
||||
gtk_check_menu_item_set_active (check_menu_item, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
|
||||
gtk_action_unblock_activate (action);
|
||||
|
||||
if (!gtk_activatable_get_use_action_appearance (activatable))
|
||||
return;
|
||||
|
||||
gtk_check_menu_item_set_draw_as_radio (check_menu_item,
|
||||
gtk_toggle_action_get_draw_as_radio (GTK_TOGGLE_ACTION (action)));
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
gtk_check_menu_item_new (void)
|
||||
{
|
||||
@ -351,6 +419,8 @@ gtk_check_menu_item_activate (GtkMenuItem *menu_item)
|
||||
gtk_check_menu_item_toggled (check_menu_item);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (check_menu_item));
|
||||
|
||||
GTK_MENU_ITEM_CLASS (gtk_check_menu_item_parent_class)->activate (menu_item);
|
||||
|
||||
g_object_notify (G_OBJECT (check_menu_item), "active");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user