gtk _get_type() function implementation

1.8k views Asked by At

I just started learning GTK. I was going through source code of gtk+3.0.0, I found implementation of _get_type() methods for some gtk object types but some do not have an implementation of this method e.g GtkRange. Is there any reason for this? As far I understood from GObject Reference Manual, _get_type() method registers object type in type system.

1

There are 1 answers

0
ebassi On

the get_type() function is needed for all types registered as a GType. GObject (the library) provides convenience macros to generate the correct get_type() function implementation taking into account things like thread-safe initialization, or dynamic type registration.

the macro that is used for GObject (the type) subclasses is G_DEFINE_TYPE(), but inside GTK+ you will also find G_DEFINE_TYPE_WITH_CODE(), used generally when the type also implements interfaces; G_DEFINE_ABSTRACT_TYPE() and G_DEFINE_ABSTRACT_TYPE_WITH_CODE(), used for abstract types; and, more recently, G_DEFINE_TYPE_WITH_PRIVATE() and G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(), which define GObject subclasses with private data, avoiding the call to g_type_class_add_private() inside the class initialization function.

boxed types (GType wrappers around Plain Old Structures) also have G_DEFINE_BOXED_TYPE(), and interface types have G_DEFINE_INTERFACE().

more information is available in the API reference for GObject:

https://docs.gtk.org/gobject/func.DEFINE_TYPE.html