]> Pileus Git - ~andy/gtk/blobdiff - modules/other/gail/gailexpander.c
Deprecate widget flag: GTK_WIDGET_VISIBLE
[~andy/gtk] / modules / other / gail / gailexpander.c
index 8d43e2fdc8f45411b22bea9aaea584c841b21a54..fd42659a04c8f050be3cbd80f23bc62031a96b81 100644 (file)
@@ -17,6 +17,8 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#include "config.h"
+
 #include <string.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
@@ -24,7 +26,7 @@
 #include <libgail-util/gailmisc.h>
 
 static void                  gail_expander_class_init       (GailExpanderClass *klass);
-static void                  gail_expander_object_init      (GailExpander      *expander);
+static void                  gail_expander_init             (GailExpander      *expander);
 
 static G_CONST_RETURN gchar* gail_expander_get_name         (AtkObject         *obj);
 static gint                  gail_expander_get_n_children   (AtkObject         *obj)
@@ -43,6 +45,7 @@ static void                  gail_expander_real_initialize  (AtkObject         *
 static void                  gail_expander_finalize         (GObject           *object);
 static void                  gail_expander_init_textutil    (GailExpander      *expander,
                                                              GtkExpander       *widget);
+static G_CONST_RETURN gchar* gail_expander_get_full_text    (GtkExpander       *widget);
 
 static void                  atk_action_interface_init  (AtkActionIface *iface);
 static gboolean              gail_expander_do_action    (AtkAction      *action,
@@ -109,55 +112,9 @@ static AtkAttributeSet* gail_expander_get_run_attributes
 static AtkAttributeSet* gail_expander_get_default_attributes
                                                    (AtkText           *text);
 
-static GailContainer* parent_class = NULL;
-
-GType
-gail_expander_get_type (void)
-{
-  static GType type = 0;
-
-  if (!type)
-    {
-      static const GTypeInfo tinfo =
-      {
-        sizeof (GailExpanderClass),
-        (GBaseInitFunc) NULL, /* base init */
-        (GBaseFinalizeFunc) NULL, /* base finalize */
-        (GClassInitFunc) gail_expander_class_init, /* class init */
-        (GClassFinalizeFunc) NULL, /* class finalize */
-        NULL, /* class data */
-        sizeof (GailExpander), /* instance size */
-        0, /* nb preallocs */
-        (GInstanceInitFunc) gail_expander_object_init, /* instance init */
-        NULL /* value table */
-      };
-
-      static const GInterfaceInfo atk_action_info =
-      {
-        (GInterfaceInitFunc) atk_action_interface_init,
-        (GInterfaceFinalizeFunc) NULL,
-        NULL
-      };
-
-      static const GInterfaceInfo atk_text_info =
-      {
-        (GInterfaceInitFunc) atk_text_interface_init,
-        (GInterfaceFinalizeFunc) NULL,
-        NULL
-      };
-
-      type = g_type_register_static (GAIL_TYPE_CONTAINER,
-                                     "GailExpander", &tinfo, 0);
-
-      g_type_add_interface_static (type, ATK_TYPE_ACTION,
-                                   &atk_action_info);
-      g_type_add_interface_static (type, ATK_TYPE_TEXT,
-                                   &atk_text_info);
-
-    }
-
-  return type;
-}
+G_DEFINE_TYPE_WITH_CODE (GailExpander, gail_expander, GAIL_TYPE_CONTAINER,
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_interface_init))
 
 static void
 gail_expander_class_init (GailExpanderClass *klass)
@@ -171,8 +128,6 @@ gail_expander_class_init (GailExpanderClass *klass)
 
   gobject_class->finalize = gail_expander_finalize;
 
-  parent_class = g_type_class_peek_parent (klass);
-
   class->get_name = gail_expander_get_name;
   class->get_n_children = gail_expander_get_n_children;
   class->ref_child = gail_expander_ref_child;
@@ -182,7 +137,7 @@ gail_expander_class_init (GailExpanderClass *klass)
 }
 
 static void
-gail_expander_object_init (GailExpander *expander)
+gail_expander_init (GailExpander *expander)
 {
   expander->activate_description = NULL;
   expander->activate_keybinding = NULL;
@@ -190,29 +145,13 @@ gail_expander_object_init (GailExpander *expander)
   expander->textutil = NULL;
 }
 
-AtkObject* 
-gail_expander_new (GtkWidget *widget)
-{
-  GObject *object;
-  AtkObject *accessible;
-
-  g_return_val_if_fail (GTK_IS_EXPANDER (widget), NULL);
-
-  object = g_object_new (GAIL_TYPE_EXPANDER, NULL);
-
-  accessible = ATK_OBJECT (object);
-  atk_object_initialize (accessible, widget);
-
-  return accessible;
-}
-
 static G_CONST_RETURN gchar*
 gail_expander_get_name (AtkObject *obj)
 {
   G_CONST_RETURN gchar *name;
   g_return_val_if_fail (GAIL_IS_EXPANDER (obj), NULL);
 
-  name = ATK_OBJECT_CLASS (parent_class)->get_name (obj);
+  name = ATK_OBJECT_CLASS (gail_expander_parent_class)->get_name (obj);
   if (name != NULL)
     return name;
   else
@@ -231,7 +170,7 @@ gail_expander_get_name (AtkObject *obj)
 
       g_return_val_if_fail (GTK_IS_EXPANDER (widget), NULL);
 
-      return gtk_expander_get_label (GTK_EXPANDER (widget)); 
+      return gail_expander_get_full_text (GTK_EXPANDER (widget));
     }
 }
 
@@ -255,7 +194,7 @@ gail_expander_get_n_children (AtkObject* obj)
   /* See if there is a label - if there is, reduce our count by 1
    * since we don't want the label included with the children.
    */
-  if (gtk_expander_get_label_widget (widget))
+  if (gtk_expander_get_label_widget (GTK_EXPANDER (widget)))
     count -= 1;
 
   return count; 
@@ -283,7 +222,7 @@ gail_expander_ref_child (AtkObject *obj,
   /* See if there is a label - if there is, we need to skip it
    * since we don't want the label included with the children.
    */
-  label = gtk_expander_get_label_widget (widget);
+  label = gtk_expander_get_label_widget (GTK_EXPANDER (widget));
   if (label) {
     count = g_list_length (children);
     for (index = 0; index <= i; index++) {
@@ -315,7 +254,7 @@ gail_expander_real_initialize (AtkObject *obj,
   GailExpander *gail_expander = GAIL_EXPANDER (obj);
   GtkWidget  *expander;
 
-  ATK_OBJECT_CLASS (parent_class)->initialize (obj, data);
+  ATK_OBJECT_CLASS (gail_expander_parent_class)->initialize (obj, data);
 
   expander = GTK_WIDGET (data);
   if (GTK_WIDGET_MAPPED (expander))
@@ -355,7 +294,7 @@ gail_expander_real_notify_gtk (GObject    *obj,
       const gchar* label_text;
 
 
-      label_text = gtk_expander_get_label (expander);
+      label_text = gail_expander_get_full_text (expander);
 
       gail_expander = GAIL_EXPANDER (atk_obj);
       if (gail_expander->textutil)
@@ -382,7 +321,20 @@ gail_expander_real_notify_gtk (GObject    *obj,
       g_signal_emit_by_name (atk_obj, "visible_data_changed");
     }
   else
-    GAIL_WIDGET_CLASS (parent_class)->notify_gtk (obj, pspec);
+    GAIL_WIDGET_CLASS (gail_expander_parent_class)->notify_gtk (obj, pspec);
+}
+
+static G_CONST_RETURN gchar*
+gail_expander_get_full_text (GtkExpander *widget)
+{
+  GtkWidget *label_widget;
+
+  label_widget = gtk_expander_get_label_widget (widget);
+
+  if (!GTK_IS_LABEL (label_widget))
+    return NULL;
+
+  return gtk_label_get_text (GTK_LABEL (label_widget));
 }
 
 static void
@@ -392,15 +344,13 @@ gail_expander_init_textutil (GailExpander *expander,
   const gchar *label_text;
 
   expander->textutil = gail_text_util_new ();
-  label_text = gtk_expander_get_label (widget);
+  label_text = gail_expander_get_full_text (widget);
   gail_text_util_text_setup (expander->textutil, label_text);
 }
 
 static void
 atk_action_interface_init (AtkActionIface *iface)
 {
-  g_return_if_fail (iface != NULL);
-
   iface->do_action = gail_expander_do_action;
   iface->get_n_actions = gail_expander_get_n_actions;
   iface->get_description = gail_expander_get_description;
@@ -424,7 +374,7 @@ gail_expander_do_action (AtkAction *action,
      */
     return FALSE;
 
-  if (!GTK_WIDGET_IS_SENSITIVE (widget) || !GTK_WIDGET_VISIBLE (widget))
+  if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
     return FALSE;
 
   expander = GAIL_EXPANDER (action);
@@ -434,7 +384,7 @@ gail_expander_do_action (AtkAction *action,
       if (expander->action_idle_handler)
         return_value = FALSE;
       else
-       expander->action_idle_handler = g_idle_add (idle_do_action, expander);
+       expander->action_idle_handler = gdk_threads_add_idle (idle_do_action, expander);
       break;
     default:
       return_value = FALSE;
@@ -449,24 +399,17 @@ idle_do_action (gpointer data)
   GtkWidget *widget;
   GailExpander *gail_expander;
 
-  GDK_THREADS_ENTER ();
-
   gail_expander = GAIL_EXPANDER (data);
   gail_expander->action_idle_handler = 0;
 
   widget = GTK_ACCESSIBLE (gail_expander)->widget;
   if (widget == NULL /* State is defunct */ ||
-      !GTK_WIDGET_IS_SENSITIVE (widget) || !GTK_WIDGET_VISIBLE (widget))
-    {
-      GDK_THREADS_LEAVE ();
-      return FALSE;
-    }
+      !gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
+    return FALSE;
 
   gtk_widget_activate (widget);
 
-  GDK_THREADS_LEAVE ();
-
-  return FALSE; 
+  return FALSE;
 }
 
 static gint
@@ -596,7 +539,7 @@ gail_expander_ref_state_set (AtkObject *obj)
   GtkWidget *widget;
   GtkExpander *expander;
 
-  state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (obj);
+  state_set = ATK_OBJECT_CLASS (gail_expander_parent_class)->ref_state_set (obj);
   widget = GTK_ACCESSIBLE (obj)->widget;
 
   if (widget == NULL)
@@ -619,7 +562,6 @@ gail_expander_ref_state_set (AtkObject *obj)
 static void
 atk_text_interface_init (AtkTextIface *iface)
 {
-  g_return_if_fail (iface != NULL);
   iface->get_text = gail_expander_get_text;
   iface->get_character_at_offset = gail_expander_get_character_at_offset;
   iface->get_text_before_offset = gail_expander_get_text_before_offset;
@@ -650,7 +592,7 @@ gail_expander_get_text (AtkText *text,
   if (!expander->textutil) 
     gail_expander_init_textutil (expander, GTK_EXPANDER (widget));
 
-  label_text = gtk_expander_get_label (GTK_EXPANDER (widget));
+  label_text = gail_expander_get_full_text (GTK_EXPANDER (widget));
 
   if (label_text == NULL)
     return NULL;
@@ -946,5 +888,5 @@ gail_expander_finalize (GObject *object)
   if (expander->textutil)
     g_object_unref (expander->textutil);
 
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gail_expander_parent_class)->finalize (object);
 }