Inicializadores de clases/instancias
- Guía de accesibilidad para los desarrolladores de GNOME
- ¿Qué es la accesibilidad?
- Ejemplos que usan la API de accesibilidad
- Implementar un objeto ATK
Deberá tener creada un inicializador de clases para el GObject si su implementación de AtkObject:
-
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.
For example, if your ATK implementation needs to over-ride the AtkObject function get_name(), then the class initializer would look like:
Ejemplo 1-8 Inicializador de clase que sobreescribe la función padre get_name()myatkimp_mytype_class_init (GailLabelClass *klass) { AtkObjectClass *class = ATK_OBJECT_CLASS (klass); class->get_name = myatkimp_mytype_get_name; }
-
Requere una función parent->init, parent->notify_gtk, o parent->finalize. Este ejemplo define las tres:
Ejemplo 1-9 Class initializer that defines its own init(), notify_gtk() and finalize() functionsstatic ParentObjectType *parent_class = NULL; myatkimp_mytype_class_init (GailLabelClass *klass) { ParentObjectType *parent_class = (ParentObjectType*)klass; /* * Caching the parent_class is necessary if the init, * notify_gtk, or finalize functions are set up. */ parent_class = g_type_class_ref (MYATKIMP_TYPE_PARENT); parent_class->init = myatkimp_mytype_widget_init; parent_class->notify_gtk = myatkimp_mytype_real_notify_gtk; parent_class->finalize = myatkimp_mytype_finalize; }
-
parent->init
A parent->init() function may be necessary if the ATK implementation needs to do either of the following:
- Cache any data obtained from a backing GTK widget.
- Escuche cualquier señal desde el widget GTK de respaldo.
Aquí hay un ejemplo de ambas:
Ejemplo 1-10 Una función init() personalizadavoid gail_tree_view_widget_init (MyatkimpMytype *mytype, GtkWidget *gtk_widget) { /* Make sure to call the parent's init function */ parent_class->init (widget, gtk_widget); /* Cache a value in the ATK implementation */ mytype->cached_value = gtk_widget_function_call(); /* Listen to a signal */ gtk_signal_connect (GTK_OBJECT (gtk_widget), "signal-type", GTK_SIGNAL_FUNC (_myatkimp_mytype_signal_type), NULL); }
In this example, if the specified signal-type signal were generated on the backing gtk_widget, then the _myatkimp_mytype_signal_type() function would be called.
-
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:
Ejemplo 1-11 Una función notify_gtk() personalizadavoid 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) { /* Gestionar el cambio de la propiedad. */ } else { parent_class->notify_gtk (obj, pspec); } }
-
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:
Ejemplo 1-12 Una función finalize() personalizadavoid 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); }
-