ATK Implementation for a Specific Object
所有 GObject 均要实现一个 get_type() 函数。使用上面的命名惯例将函数命名为 myatkimp_mytype_get_type()。
In this function, you specify which interfaces your object implements. If the following logic were included in this get_type() function, this object would implement the ATK_TEXT interface:
Example 1-5 get_type() 函数示例
static const GInterfaceInfo atk_text_info = { (GInterfaceInitFunc) atk_text_interface_init, (GInterfaceFinalizeFunc) NULL, NULL }; g_type_add_interface_static (type, ATK_TYPE_TEXT, &atk_text_info);
函数 atk_text_interface_init() 需要实现的函数原型如下:
void atk_text_interface_init (AtkTextIface *iface);
This function would connect the interface function calls to the specific implementation as follows:
Example 1-6 连接自定义接口与一个 AtkObject 实现
void atk_text_interface_init (AtkTextIface *iface) { g_return_if_fail (iface != NULL); iface->get_text = myatkimp_mytype_get_text; iface->get_character_at_offset = myatkimp_mytype_get_character_at_offset; ... }
Then the functions myatkimp_mytype_get_text(), myatkimp_mytype_get_character_at_offset(), and the rest of the ATK_TEXT interface functions would need to be implemented.