Small GNOME foot in banner [Making Applications Accessible]
back next

Anonymous (run-time) Inheritance from GAIL (continued)

  • get a reference to your parent type's accessible type
  • use this type to do some magic in your subclass's get_type method
  • you can't add private data directly to your struct, but you can use g_object_add_data
  • 	      
    GType
    zvt_accessible_get_type (void)
    {
      static GType type = 0;
    
      if (!type)
      {
        static GTypeInfo tinfo =
        {
          0, /* class size */
          (GBaseInitFunc) NULL, /* base init */
          (GBaseFinalizeFunc) NULL, /* base finalize */
          (GClassInitFunc) zvt_accessible_class_init, /* class init */
          (GClassFinalizeFunc) NULL, /* class finalize */
          NULL, /* class data */
          0, /* instance size */
          0, /* nb preallocs */
          (GInstanceInitFunc) NULL, /* instance init */
          NULL /* value table */
        };
    
        static const GInterfaceInfo atk_text_info =
        {
          (GInterfaceInitFunc) atk_text_interface_init,
          (GInterfaceFinalizeFunc) NULL,
          NULL
        };
    
        /*
         * Figure out the size of the class and instance
         * we are deriving from
         */
        AtkObjectFactory *factory;
        GType derived_type;
        GTypeQuery query;
        GType derived_atk_type;
    
        derived_type = g_type_parent (ZVT_TYPE_TERM);
        factory = atk_registry_get_factory (atk_get_default_registry (), derived_type);
        derived_atk_type = atk_object_factory_get_accessible_type (factory);
        g_type_query (derived_atk_type, &query);
        tinfo.class_size = query.class_size;
        tinfo.instance_size = query.instance_size;
    
        type = g_type_register_static (derived_atk_type, "ZvtAccessible", &tinfo, 0);
        g_type_add_interface_static (type, ATK_TYPE_TEXT,
                                     &atk_text_info);
      }
    
      return type;
    }
    
st