]> Pileus Git - ~andy/gtk/blobdiff - modules/other/gail/gailtogglebutton.c
Remove a bunch of crazy code from gail
[~andy/gtk] / modules / other / gail / gailtogglebutton.c
index 13d509c74416f526523c658914f38d12dff766b1..63f8d441bb39e03209d2901590e4a02af894cdf8 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include "config.h"
+
 #include <string.h>
 #include <gtk/gtk.h>
 #include "gailtogglebutton.h"
 
 static void      gail_toggle_button_class_init        (GailToggleButtonClass *klass);
 
+static void      gail_toggle_button_init              (GailToggleButton      *button);
+
 static void      gail_toggle_button_toggled_gtk       (GtkWidget             *widget);
 
 static void      gail_toggle_button_real_notify_gtk   (GObject               *obj,
@@ -33,35 +37,7 @@ static void      gail_toggle_button_real_initialize   (AtkObject             *ob
 
 static AtkStateSet* gail_toggle_button_ref_state_set  (AtkObject             *accessible);
 
-static GailButtonClass *parent_class = NULL;
-
-GType
-gail_toggle_button_get_type (void)
-{
-  static GType type = 0;
-
-  if (!type)
-    {
-      static const GTypeInfo tinfo =
-      {
-        sizeof (GailToggleButtonClass),
-        (GBaseInitFunc) NULL, /* base init */
-        (GBaseFinalizeFunc) NULL, /* base finalize */
-        (GClassInitFunc) gail_toggle_button_class_init, /* class init */
-        (GClassFinalizeFunc) NULL, /* class finalize */
-        NULL, /* class data */
-        sizeof (GailToggleButton), /* instance size */
-        0, /* nb preallocs */
-        (GInstanceInitFunc) NULL, /* instance init */
-        NULL /* value table */
-      };
-
-      type = g_type_register_static (GAIL_TYPE_BUTTON,
-                                     "GailToggleButton", &tinfo, 0);
-    }
-
-  return type;
-}
+G_DEFINE_TYPE (GailToggleButton, gail_toggle_button, GAIL_TYPE_BUTTON)
 
 static void
 gail_toggle_button_class_init (GailToggleButtonClass *klass)
@@ -72,33 +48,20 @@ gail_toggle_button_class_init (GailToggleButtonClass *klass)
   widget_class = (GailWidgetClass*)klass;
   widget_class->notify_gtk = gail_toggle_button_real_notify_gtk;
 
-  parent_class = g_type_class_peek_parent (klass);
-
   class->ref_state_set = gail_toggle_button_ref_state_set;
   class->initialize = gail_toggle_button_real_initialize;
 }
 
-AtkObject* 
-gail_toggle_button_new (GtkWidget *widget)
+static void
+gail_toggle_button_init (GailToggleButton *button)
 {
-  GObject *object;
-  AtkObject *accessible;
-
-  g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (widget), NULL);
-
-  object = g_object_new (GAIL_TYPE_TOGGLE_BUTTON, NULL);
-
-  accessible = ATK_OBJECT (object);
-  atk_object_initialize (accessible, widget);
-
-  return accessible;
 }
 
 static void
 gail_toggle_button_real_initialize (AtkObject *obj,
                                     gpointer  data)
 {
-  ATK_OBJECT_CLASS (parent_class)->initialize (obj, data);
+  ATK_OBJECT_CLASS (gail_toggle_button_parent_class)->initialize (obj, data);
 
   g_signal_connect (data,
                     "toggled",
@@ -121,7 +84,7 @@ gail_toggle_button_toggled_gtk (GtkWidget       *widget)
 
   accessible = gtk_widget_get_accessible (widget);
   atk_object_notify_state_change (accessible, ATK_STATE_CHECKED, 
-                                  toggle_button->active);
+                                  gtk_toggle_button_get_active (toggle_button));
 } 
 
 static AtkStateSet*
@@ -131,8 +94,8 @@ gail_toggle_button_ref_state_set (AtkObject *accessible)
   GtkToggleButton *toggle_button;
   GtkWidget *widget;
 
-  state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (accessible);
-  widget = GTK_ACCESSIBLE (accessible)->widget;
+  state_set = ATK_OBJECT_CLASS (gail_toggle_button_parent_class)->ref_state_set (accessible);
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
  
   if (widget == NULL)
     return state_set;
@@ -143,7 +106,10 @@ gail_toggle_button_ref_state_set (AtkObject *accessible)
     atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
 
   if (gtk_toggle_button_get_inconsistent (toggle_button))
-    atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
+    {
+      atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
+      atk_state_set_add_state (state_set, ATK_STATE_INDETERMINATE);
+    }
  
   return state_set;
 }
@@ -154,12 +120,24 @@ gail_toggle_button_real_notify_gtk (GObject           *obj,
 {
   GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
   AtkObject *atk_obj;
+  gboolean sensitive;
+  gboolean inconsistent;
 
   atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));
+  sensitive = gtk_widget_get_sensitive (GTK_WIDGET (toggle_button));
+  inconsistent = gtk_toggle_button_get_inconsistent (toggle_button);
 
   if (strcmp (pspec->name, "inconsistent") == 0)
-    atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED,
-                       !gtk_toggle_button_get_inconsistent (toggle_button));
+    {
+      atk_object_notify_state_change (atk_obj, ATK_STATE_INDETERMINATE, inconsistent);
+      atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
+    }
+  else if (strcmp (pspec->name, "sensitive") == 0)
+    {
+      /* Need to override gailwidget behavior of notifying for ENABLED */
+      atk_object_notify_state_change (atk_obj, ATK_STATE_SENSITIVE, sensitive);
+      atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
+    }
   else
-    GAIL_WIDGET_CLASS (parent_class)->notify_gtk (obj, pspec);
+    GAIL_WIDGET_CLASS (gail_toggle_button_parent_class)->notify_gtk (obj, pspec);
 }