Examples that Use the Accessibility API

As noted earlier, you should have little or no work to do to make your application accessible if you use the GTK widget set, or any other widget library that implements the ATK interfaces. The two most common things you may have to do in this case are:

  • provide descriptions of some controls and images using atk_object_set_description() or atk_image_set_description():

    Example 1-3Setting the accessible description for a button
    {
       AtkObject *obj;
       obj = gtk_widget_get_accessible(button);
       atk_object_set_description(obj,_("Opens Preferences dialog"));
    }
    

  • Specify relationships between any unusual groupings of widgets using atk_relation_new() and atk_relation_set_add():

    Example 1-4Specifying accessible relationship between two controls
    {
      GtkWidget *widget;
      GtkLabel *label;
    
      AtkObject *atk_widget, *atk_label;
      AtkRelationSet *relation_set;
      AtkRelation *relation;
      AtkObject *targets[1];
    
      atk_widget = gtk_widget_get_accessible (widget);
      atk_label = gtk_widget_get_accessible (GTK_WIDGET(label));
    
      relation_set = atk_object_ref_relation_set (atk_label);
      targets[0] = atk_widget;
    
      relation = atk_relation_new(targets,1, ATK_RELATION_LABEL_FOR);
      atk_relation_set_add(relation_set,relation);
      g_object_unref(G_OBJECT(relation));
    }
    

The examples in the rest of this section are mostly to give you a flavor of the scope of the ATK. They cover techniques that you may never need to use as an application developer, although they may be of interest if you are writing your own custom widgets (see Making Custom Components Accessible) or if you want to write an assistive technology application.