]> Pileus Git - ~andy/gtk/blobdiff - modules/other/gail/gailbutton.c
gail: we cant access button->in_button directly now.
[~andy/gtk] / modules / other / gail / gailbutton.c
index 5583d56b6fd7bbc69cba23507ea374e02dd1564c..8a187261c3a09ab515e29cf82e298a7162954d2e 100644 (file)
@@ -154,10 +154,8 @@ gail_button_class_init (GailButtonClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
-  GailWidgetClass *widget_class;
   GailContainerClass *container_class;
 
-  widget_class = (GailWidgetClass*)klass;
   container_class = (GailContainerClass*)klass;
 
   gobject_class->finalize = gail_button_finalize;
@@ -200,7 +198,7 @@ gail_button_get_name (AtkObject *obj)
       GtkWidget *widget;
       GtkWidget *child;
 
-      widget = GTK_ACCESSIBLE (obj)->widget;
+      widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
       if (widget == NULL)
         /*
          * State is defunct
@@ -236,21 +234,28 @@ gail_button_get_name (AtkObject *obj)
 static gboolean
 gail_button_is_default_press (GtkWidget *widget)
 {
+  GtkArrowType arrow_type;
   GtkWidget  *child;
   GtkWidget  *parent;
   gboolean ret = FALSE;
   const gchar *parent_type_name;
 
-  child = GTK_BIN (widget)->child;
-  if (GTK_IS_ARROW (child) &&
-      GTK_ARROW (child)->arrow_type == GTK_ARROW_DOWN)
+  child = gtk_bin_get_child (GTK_BIN (widget));
+  if (GTK_IS_ARROW (child))
     {
-      parent = gtk_widget_get_parent (widget);
-      if (parent)
+      g_object_get (child,
+                    "arrow_type", &arrow_type,
+                    NULL);
+
+      if (arrow_type == GTK_ARROW_DOWN)
         {
-          parent_type_name = g_type_name (G_OBJECT_TYPE (parent));
-          if (strcmp (parent_type_name, "ColorCombo"))
-            return TRUE;
+          parent = gtk_widget_get_parent (widget);
+          if (parent)
+            {
+              parent_type_name = g_type_name (G_OBJECT_TYPE (parent));
+              if (g_strcmp0 (parent_type_name, "ColorCombo"))
+                return TRUE;
+            }
         }
     }
 
@@ -291,7 +296,7 @@ gail_button_real_initialize (AtkObject *obj,
   label = get_label_from_button (widget, 0, FALSE);
   if (GTK_IS_LABEL (label))
     {
-      if (GTK_WIDGET_MAPPED (label))
+      if (gtk_widget_get_mapped (label))
         gail_button_init_textutil (button, label);
       else 
         g_signal_connect (label,
@@ -454,14 +459,14 @@ gail_button_do_action (AtkAction *action,
   GailButton *button;
   gboolean return_value = TRUE;
 
-  widget = GTK_ACCESSIBLE (action)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
   if (widget == NULL)
     /*
      * State is defunct
      */
     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;
 
   button = GAIL_BUTTON (action); 
@@ -475,7 +480,7 @@ gail_button_do_action (AtkAction *action,
        {
          button->action_queue = g_queue_new ();
        }
-      g_queue_push_head (button->action_queue, (gpointer) i);
+      g_queue_push_head (button->action_queue, GINT_TO_POINTER(i));
       if (!button->action_idle_handler)
        button->action_idle_handler = gdk_threads_add_idle (idle_do_action, button);
       break;
@@ -493,27 +498,35 @@ idle_do_action (gpointer data)
   GtkWidget *widget;
   GailButton *gail_button;
   GdkEvent tmp_event;
+  GdkWindow *window;
 
   gail_button = GAIL_BUTTON (data);
   gail_button->action_idle_handler = 0;
-  widget = GTK_ACCESSIBLE (gail_button)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (gail_button));
+  window = gtk_widget_get_window (widget);
+
   tmp_event.button.type = GDK_BUTTON_RELEASE;
-  tmp_event.button.window = widget->window;
+  tmp_event.button.window = window;
   tmp_event.button.button = 1;
   tmp_event.button.send_event = TRUE;
   tmp_event.button.time = GDK_CURRENT_TIME;
   tmp_event.button.axes = NULL;
-  
+
+  g_object_ref (gail_button);
+
   if (widget == NULL /* State is defunct */ ||
-      !GTK_WIDGET_IS_SENSITIVE (widget) || !GTK_WIDGET_VISIBLE (widget))
-    return FALSE;
+      !gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
+    {
+      g_object_unref (gail_button);
+      return FALSE;
+    }
   else
     gtk_widget_event (widget, &tmp_event);
 
   button = GTK_BUTTON (widget); 
   while (!g_queue_is_empty (gail_button->action_queue)) 
     {
-      gint action_number = (gint) g_queue_pop_head (gail_button->action_queue);
+      gint action_number = GPOINTER_TO_INT(g_queue_pop_head (gail_button->action_queue));
       if (gail_button->default_is_press)
         {
           if (action_number == 0)
@@ -526,14 +539,16 @@ idle_do_action (gpointer data)
        case 0:
          /* first a press */ 
 
+          /* FIXME: Do not access public member
          button->in_button = TRUE;
-         gtk_button_enter (button);
+          */
+         g_signal_emit_by_name (button, "enter");
          /*
           * Simulate a button press event. calling gtk_button_pressed() does
           * not get the job done for a GtkOptionMenu.  
           */
          tmp_event.button.type = GDK_BUTTON_PRESS;
-         tmp_event.button.window = widget->window;
+         tmp_event.button.window = window;
          tmp_event.button.button = 1;
          tmp_event.button.send_event = TRUE;
          tmp_event.button.time = GDK_CURRENT_TIME;
@@ -544,18 +559,22 @@ idle_do_action (gpointer data)
          /* then a release */
          tmp_event.button.type = GDK_BUTTON_RELEASE;
          gtk_widget_event (widget, &tmp_event);
+          /* FIXME: Do not access public member
          button->in_button = FALSE;
-         gtk_button_leave (button); 
+          */
+         g_signal_emit_by_name (button, "leave");
          break;
        case 1:
+          /* FIXME: Do not access public member
          button->in_button = TRUE;
-         gtk_button_enter (button);
+          */
+         g_signal_emit_by_name (button, "enter");
          /*
           * Simulate a button press event. calling gtk_button_pressed() does
           * not get the job done for a GtkOptionMenu.  
           */
          tmp_event.button.type = GDK_BUTTON_PRESS;
-         tmp_event.button.window = widget->window;
+         tmp_event.button.window = window;
          tmp_event.button.button = 1;
          tmp_event.button.send_event = TRUE;
          tmp_event.button.time = GDK_CURRENT_TIME;
@@ -564,15 +583,17 @@ idle_do_action (gpointer data)
          gtk_widget_event (widget, &tmp_event);
          break;
        case 2:
+          /* FIXME: Do not access public member
          button->in_button = FALSE;
-         gtk_button_leave (button);
+          */
+         g_signal_emit_by_name (button, "leave");
          break;
        default:
          g_assert_not_reached ();
          break;
        }
     }
-
+  g_object_unref (gail_button);
   return FALSE;
 }
 
@@ -642,7 +663,7 @@ gail_button_get_keybinding (AtkAction *action,
         GtkWidget *label;
         guint key_val; 
 
-        widget = GTK_ACCESSIBLE (button)->widget;
+        widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (button));
         if (widget == NULL)
           /*
            * State is defunct
@@ -655,7 +676,7 @@ gail_button_get_keybinding (AtkAction *action,
         if (GTK_IS_LABEL (label))
           {
             key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label)); 
-            if (key_val != GDK_VoidSymbol)
+            if (key_val != GDK_KEY_VoidSymbol)
               return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
           }
         if (return_value == NULL)
@@ -675,10 +696,7 @@ gail_button_get_keybinding (AtkAction *action,
                     target = atk_relation_get_target (relation);
             
                     target_object = g_ptr_array_index (target, 0);
-                    if (GTK_IS_ACCESSIBLE (target_object))
-                      {
-                        label = GTK_ACCESSIBLE (target_object)->widget;
-                      } 
+                    label = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object));
                   }
                 g_object_unref (set);
               }
@@ -686,7 +704,7 @@ gail_button_get_keybinding (AtkAction *action,
             if (GTK_IS_LABEL (label))
               {
                 key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label)); 
-                if (key_val != GDK_VoidSymbol)
+                if (key_val != GDK_KEY_VoidSymbol)
                   return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
               }
           }
@@ -799,7 +817,7 @@ gail_button_get_n_children (AtkObject* obj)
 
   g_return_val_if_fail (GAIL_IS_BUTTON (obj), 0);
 
-  widget = GTK_ACCESSIBLE (obj)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
   if (widget == NULL)
     /*
      * State is defunct
@@ -830,7 +848,7 @@ gail_button_ref_child (AtkObject *obj,
 
   g_return_val_if_fail (GAIL_IS_BUTTON (obj), NULL);
 
-  widget = GTK_ACCESSIBLE (obj)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
   if (widget == NULL)
     /*
      * State is defunct
@@ -871,22 +889,17 @@ gail_button_ref_state_set (AtkObject *obj)
 {
   AtkStateSet *state_set;
   GtkWidget *widget;
-  GtkButton *button;
 
   state_set = ATK_OBJECT_CLASS (gail_button_parent_class)->ref_state_set (obj);
-  widget = GTK_ACCESSIBLE (obj)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
 
   if (widget == NULL)
     return state_set;
 
-  button = GTK_BUTTON (widget);
-
-  if (GTK_WIDGET_STATE (widget) == GTK_STATE_ACTIVE)
+  if (gtk_widget_get_state (widget) == GTK_STATE_ACTIVE)
     atk_state_set_add_state (state_set, ATK_STATE_ARMED);
 
-  if (GTK_WIDGET_CAN_FOCUS(widget))
-    atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
-  else
+  if (!gtk_widget_get_can_focus (widget))
     atk_state_set_remove_state (state_set, ATK_STATE_SELECTABLE);
 
 
@@ -904,7 +917,7 @@ gail_button_pressed_enter_handler (GtkWidget       *widget)
 {
   AtkObject *accessible;
 
-  if (GTK_WIDGET_STATE (widget) == GTK_STATE_ACTIVE)
+  if (gtk_widget_get_state (widget) == GTK_STATE_ACTIVE)
     {
       accessible = gtk_widget_get_accessible (widget);
       atk_object_notify_state_change (accessible, ATK_STATE_ARMED, TRUE);
@@ -975,8 +988,7 @@ gail_button_get_image_description (AtkImage *image) {
   GtkImage  *button_image;
   AtkObject *obj;
 
-  widget = GTK_ACCESSIBLE (image)->widget;
-
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
   if (widget == NULL)
     /*
      * State is defunct
@@ -1004,7 +1016,7 @@ gail_button_get_image_position (AtkImage     *image,
   GtkImage  *button_image;
   AtkObject *obj;
 
-  widget = GTK_ACCESSIBLE (image)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
 
   if (widget == NULL)
     {
@@ -1039,7 +1051,7 @@ gail_button_get_image_size (AtkImage *image,
   GtkImage  *button_image;
   AtkObject *obj;
 
-  widget = GTK_ACCESSIBLE (image)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
 
   if (widget == NULL)
     {
@@ -1073,7 +1085,7 @@ gail_button_set_image_description (AtkImage    *image,
   GtkImage  *button_image;
   AtkObject *obj;
 
-  widget = GTK_ACCESSIBLE (image)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
 
   if (widget == NULL)
     /*
@@ -1119,7 +1131,8 @@ gail_button_get_text (AtkText *text,
   GailButton *button;
   const gchar *label_text;
 
-  widget = GTK_ACCESSIBLE (text)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
+
   if (widget == NULL)
     /* State is defunct */
     return NULL;
@@ -1154,9 +1167,9 @@ gail_button_get_text_before_offset (AtkText         *text,
   GtkWidget *widget;
   GtkWidget *label;
   GailButton *button;
-  
-  widget = GTK_ACCESSIBLE (text)->widget;
-  
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
+
   if (widget == NULL)
     /* State is defunct */
     return NULL;
@@ -1186,9 +1199,9 @@ gail_button_get_text_at_offset (AtkText         *text,
   GtkWidget *widget;
   GtkWidget *label;
   GailButton *button;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
  
-  widget = GTK_ACCESSIBLE (text)->widget;
-  
   if (widget == NULL)
     /* State is defunct */
     return NULL;
@@ -1219,8 +1232,8 @@ gail_button_get_text_after_offset (AtkText         *text,
   GtkWidget *label;
   GailButton *button;
 
-  widget = GTK_ACCESSIBLE (text)->widget;
-  
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
+
   if (widget == NULL)
   {
     /* State is defunct */
@@ -1248,7 +1261,8 @@ gail_button_get_character_count (AtkText *text)
   GtkWidget *widget;
   GtkWidget *label;
 
-  widget = GTK_ACCESSIBLE (text)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
+
   if (widget == NULL)
     /* State is defunct */
     return 0;
@@ -1275,8 +1289,8 @@ gail_button_get_character_extents (AtkText      *text,
   PangoRectangle char_rect;
   gint index, x_layout, y_layout;
   const gchar *label_text;
-  widget = GTK_ACCESSIBLE (text)->widget;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
 
   if (widget == NULL)
     /* State is defunct */
@@ -1307,10 +1321,12 @@ gail_button_get_offset_at_point (AtkText      *text,
   gint index, x_layout, y_layout;
   const gchar *label_text;
 
-  widget = GTK_ACCESSIBLE (text)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
+
   if (widget == NULL)
     /* State is defunct */
     return -1;
+
   label = get_label_from_button (widget, 0, FALSE);
 
   if (!GTK_IS_LABEL(label))
@@ -1345,7 +1361,8 @@ gail_button_get_run_attributes (AtkText        *text,
   GtkJustification justify;
   GtkTextDirection dir;
 
-  widget = GTK_ACCESSIBLE (text)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
+
   if (widget == NULL)
     /* State is defunct */
     return NULL;
@@ -1387,7 +1404,8 @@ gail_button_get_default_attributes (AtkText        *text)
   GtkWidget *label;
   AtkAttributeSet *at_set = NULL;
 
-  widget = GTK_ACCESSIBLE (text)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
+
   if (widget == NULL)
     /* State is defunct */
     return NULL;
@@ -1412,7 +1430,8 @@ gail_button_get_character_at_offset (AtkText               *text,
   const gchar *string;
   gchar *index;
 
-  widget = GTK_ACCESSIBLE (text)->widget;
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
+
   if (widget == NULL)
     /* State is defunct */
     return '\0';