在evince 中使用了多个 自定义类型,主要 的是
。EvWindow
。EvApplication
定义分别如下:
- struct _EvApplication {
-
GObject base_instance;
-
-
gchar *uri;
-
-
gchar *dot_dir;
-
gchar *data_dir;
-
-
#ifdef ENABLE_DBUS
-
GDBusConnection *connection;
-
guint registration_id;
-
EvMediaPlayerKeys *keys;
-
gboolean doc_registered;
-
#endif
-
-
TotemScrsaver *scr_saver;
-
-
#ifdef WITH_SMCLIENT
-
EggSMClient *smclient;
-
#endif
-
-
gchar *filechooser_open_uri;
-
gchar *filechooser_save_uri;
-
};
gtk+中使用 G_DEFINE_TYPE() 来定义自定义类型。然后调用
- gpointer g_object_new (GType object_type,
const gchar *first_property_name, ...);
来创建一个新自定义类型。
以Ev_window为例:
ev_window.c 370:
- G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
ev_window.h 54:
- #define EV_TYPE_WINDOW (ev_window_get_type())
根据G_DEFINE_TYPE的定义:
- #define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
- #define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)
- _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_)
- {_C_;}
- _G_DEFINE_TYPE_EXTENDED_END()
- #define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
-
\
-
static void type_name##_init (TypeName *self); \
-
static void type_name##_class_init (TypeName##Class *klass); \
-
static gpointer type_name##_parent_class = NULL; \
-
static void type_name##_class_intern_init (gpointer klass) \
-
{ \
-
type_name##_parent_class = g_type_class_peek_parent (klass); \
-
type_name##_class_init ((TypeName##Class*) klass); \
-
} \
-
\
-
GType \
-
type_name##_get_type (void) \
-
{ \
-
static volatile gsize g_define_type_id__volatile = 0; \
-
if (g_once_init_enter (&g_define_type_id__volatile)) \
-
{ \
-
GType g_define_type_id = \
-
g_type_register_static_simple (TYPE_PARENT, \
-
g_intern_static_string (#TypeName), \
-
sizeof (TypeName##Class), \
-
(GClassInitFunc) type_name##_class_intern_init, \
-
sizeof (TypeName), \
-
(GInstanceInitFunc) type_name##_init, \
-
(GTypeFlags) flags); \
-
{ /* custom code follows */
-
#define _G_DEFINE_TYPE_EXTENDED_END() \
-
/* following custom code */ \
-
} \
-
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
-
} \
-
return g_define_type_id__volatile; \
-
} /* closes type_name##_get_type() */
- G_DEFINE_TYPE_EXTENDED (EvWindow, ev_window, GTK_TYPE_WIDGET, 0, {});
-
将扩展成:
-
-
static void ev_window_init (EvWindow *self);
-
static void ev_window_class_init (EvWindowClass *klass);
-
static gpointer ev_window_parent_class = NULL;
-
static void ev_window_class_intern_init (gpointer klass)
-
{
-
ev_window_parent_class = g_type_class_peek_parent (klass);
-
ev_window_class_init ((EvWindowClass*) klass);
-
}
-
GType ev_window_get_type (void)
-
{
-
static volatile gsize g_define_type_id__volatile = 0;
-
if (g_once_init_enter (&g_define_type_id__volatile))
-
{
-
GType g_define_type_id =
-
g_type_register_static_simple (GTK_TYPE_WIDGET,
-
g_intern_static_string ("EvWindow"),
-
sizeof (EvWindowClass),
-
(GClassInitFunc) ev_window_class_intern_init,
-
sizeof (EvWindow),
-
(GInstanceInitFunc) ev_window_init,
-
(GTypeFlags) flags);
-
-
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
-
}
-
return g_define_type_id__volatile;
-
}
当调用
- ev_window = GTK_WIDGET (g_object_new (EV_TYPE_WINDOW,
-
"type", GTK_WINDOW_TOPLEVEL,
-
NULL));
时,
EV_TYPE_WINDOW -> ev_window_get_type -> ev_window_init。
阅读(1672) | 评论(0) | 转发(0) |