Class/Instance Initializers

You will have to set up a class initializer for the GObject if your AtkObject implementation either:

  1. Redefines any function calls defined by the object's parent. This is typically necessary when an object needs to implement a function like atk_object_get_n_accessible_children(). This is necessary if the object has children, but they are not represented with widgets.

  2. Requires a parent->init, parent->notify_gtk, or parent->finalize function.

    1. parent->init

      A parent->init() function may be necessary if the ATK implementation needs to do either of the following:

      1. Cache any data obtained from a backing GTK widget.
      2. Listen to any signals from the backing GTK widget.
    2. parent->notify_gtk

      If the ATK implementation needs to listen to any property notifications on the backing GTK object, a parent->notify_gtk() function may be necessary. For example:

      Example 1-7A custom notify_gtk() function
      void 
      myatkimp_mytype_real_notify_gtk (GObject    *obj, 
                                       GParamSpec *pspec) 
      { 
         GtkWidget *widget = GTK_WIDGET (obj); 
         AtkObject* atk_obj = gtk_widget_get_accessible (widget); 
      
         if (strcmp (pspec->name, "property-of-interest") == 0) 
         { 
            /* Handle the property change. */ 
         } 
         else 
         { 
            parent_class->notify_gtk (obj, pspec); 
         } 
      } 
      
    3. parent->finalize

      If it is necessary to free any data when a GObject instance is destroyed, then a finalize() function is needed to free the memory. For example:

      Example 1-8A custom finalize() function
      void 
      myatkimp_mytype_finalize (GObject *object) 
      { 
         MyAtkimpMyType *my_type = MYATKIMP_MYTYPE (object); 
      
         g_object_unref (my_type->cached_value); 
         G_OBJECT_CLASS (parent_class)->finalize (object); 
      }