]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcheckmenuitem.c
Bug 457086 - numpad does not work when the Thai-Lao input method is used
[~andy/gtk] / gtk / gtkcheckmenuitem.c
index a179ab24e0d48cd5441773b4cc7653d25556e11f..8bf0972688486be8076f3915c5315dc7e400a750 100644 (file)
@@ -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 guint check_menu_item_signals[LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (GtkCheckMenuItem, gtk_check_menu_item, GTK_TYPE_MENU_ITEM)
+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_update                     (GtkActivatable       *activatable,
+                                                           GtkAction            *action,
+                                                           const gchar          *property_name);
+static void gtk_check_menu_item_sync_action_properties     (GtkActivatable       *activatable,
+                                                           GtkAction            *action);
+
+static GtkActivatableIface *parent_activatable_iface;
+static guint                check_menu_item_signals[LAST_SIGNAL] = { 0 };
+
+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_update;
+  iface->sync_action_properties = gtk_check_menu_item_sync_action_properties;
+}
+
+static void
+gtk_check_menu_item_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_sync_action_properties (GtkActivatable *activatable,
+                                           GtkAction      *action)
+{
+  GtkCheckMenuItem *check_menu_item;
+
+  check_menu_item = GTK_CHECK_MENU_ITEM (activatable);
+
+  parent_activatable_iface->sync_action_properties (activatable, action);
+
+  if (!GTK_IS_TOGGLE_ACTION (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");
 }