testoptionmenu.c 3.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
#include <gtk/gtk.h>
#include "testlib.h"

/*
 * This module is used to test the accessible implementation for GtkOptionMenu
 *
 * When the GtkOption menu in the FileSelectionDialog is tabbed to, the menu
 * is opened and the second item in the menu is selected which causes the 
 * menu to be closed and the item in the GtkOptionMenu to be updated.
 */
#define NUM_VALID_ROLES 1

static void _create_event_watcher (void);
static void _check_object (AtkObject *obj);
static gint _do_menu_item_action (gpointer data);
static gboolean doing_action = FALSE;

static void 
_check_object (AtkObject *obj)
{
  AtkRole role;
  static G_CONST_RETURN char *name = NULL;
  static gboolean first_time = TRUE;

  role = atk_object_get_role (obj);
  if (role == ATK_ROLE_PUSH_BUTTON)
  /*
   * Find the specified optionmenu item
   */
    {
      AtkRole valid_roles[NUM_VALID_ROLES];
      AtkObject *atk_option_menu;
      GtkWidget *widget;

      if (name == NULL)
      {
        name = g_getenv ("TEST_ACCESSIBLE_NAME");
        if (name == NULL)
          name = "foo";
      }
      valid_roles[0] = ATK_ROLE_PUSH_BUTTON;
      atk_option_menu = find_object_by_accessible_name_and_role (obj, name,
                               valid_roles, NUM_VALID_ROLES);

      if (atk_option_menu == NULL)
        {
          g_print ("Object not found for %s\n", name);
          return;
        }
      else
        {
          g_print ("Object found for %s\n", name);
        }


      g_assert (GTK_IS_ACCESSIBLE (atk_option_menu));
      widget = GTK_ACCESSIBLE (atk_option_menu)->widget;
      g_assert (GTK_IS_OPTION_MENU (widget));

      if (first_time)
        first_time = FALSE;
      else
        return;

      /*
       * This action opens the GtkOptionMenu whose name is "foo" or whatever
       * was specified in the environment variable TEST_ACCESSIBLE_NAME
       */
      atk_action_do_action (ATK_ACTION (atk_option_menu), 0);
    }
  else if ((role == ATK_ROLE_MENU_ITEM) ||
           (role == ATK_ROLE_CHECK_MENU_ITEM) ||
           (role == ATK_ROLE_RADIO_MENU_ITEM) ||
           (role == ATK_ROLE_TEAR_OFF_MENU_ITEM))
    {
      AtkObject *parent, *child;
      AtkRole parent_role;

      /*
       * If we receive focus while waiting for the menu to be closed
       * we return immediately
       */
      if (doing_action)
        return;

      parent = atk_object_get_parent (obj);
      parent_role = atk_object_get_role (parent);
      g_assert (parent_role == ATK_ROLE_MENU);
    
      child = atk_object_ref_accessible_child (parent, 1);
      doing_action = TRUE;
      gtk_timeout_add (5000, _do_menu_item_action, child);
    }
  else
    {
      G_CONST_RETURN char *accessible_name;

      accessible_name = atk_object_get_name (obj);
      if (accessible_name)
        {
          g_print ("Name: %s\n", accessible_name);
        } 
      else if (GTK_IS_ACCESSIBLE (obj))
        {
          GtkWidget *widget = GTK_ACCESSIBLE (obj)->widget;
          g_print ("Type: %s\n", g_type_name (G_OBJECT_TYPE (widget)));
        } 
      if (role == ATK_ROLE_TABLE)
        {
          gint n_cols, i;

          n_cols = atk_table_get_n_columns (ATK_TABLE (obj));
          g_print ("Number of Columns: %d\n", n_cols);

          for (i  = 0; i < n_cols; i++)
            {
              AtkObject *header;

              header = atk_table_get_column_header (ATK_TABLE (obj), i);
              g_print ("header: %s %s\n", 
                           g_type_name (G_OBJECT_TYPE (header)),
                           atk_object_get_name (header));
            }
        }
    }
}

static gint _do_menu_item_action (gpointer data)
{
  AtkObject *obj = ATK_OBJECT (data);

  atk_action_do_action (ATK_ACTION (obj), 0);
  doing_action = FALSE;

  g_object_unref (obj);

  return FALSE;
}

static void
_create_event_watcher (void)
{
  atk_add_focus_tracker (_check_object);
}

int
gtk_module_init(gint argc, char* argv[])
{
  g_print("testoptionmenu Module loaded\n");

  _create_event_watcher();

  return 0;
}