5
* Darin Adler <darin@bentspoon.com>
7
* Copyright 2001 Ben Tea Spoons, Inc.
10
#define _EGG_MACROS_H_
12
#include <glib/gmacros.h>
16
/* Macros for defining classes. Ideas taken from Nautilus and GOB. */
18
/* Define the boilerplate type stuff to reduce typos and code size. Defines
19
* the get_type method and the parent_class static variable. */
21
#define EGG_BOILERPLATE(type, type_as_function, corba_type, \
22
parent_type, parent_type_macro, \
23
register_type_macro) \
24
static void type_as_function ## _class_init (type ## Class *klass); \
25
static void type_as_function ## _instance_init (type *object); \
26
static parent_type ## Class *parent_class = NULL; \
28
type_as_function ## _class_init_trampoline (gpointer klass, \
31
parent_class = (parent_type ## Class *)g_type_class_ref ( \
33
type_as_function ## _class_init ((type ## Class *)klass); \
36
type_as_function ## _get_type (void) \
38
static GType object_type = 0; \
39
if (object_type == 0) { \
40
static const GTypeInfo object_info = { \
41
sizeof (type ## Class), \
42
NULL, /* base_init */ \
43
NULL, /* base_finalize */ \
44
type_as_function ## _class_init_trampoline, \
45
NULL, /* class_finalize */ \
46
NULL, /* class_data */ \
48
0, /* n_preallocs */ \
49
(GInstanceInitFunc) type_as_function ## _instance_init \
51
object_type = register_type_macro \
52
(type, type_as_function, corba_type, \
53
parent_type, parent_type_macro); \
58
/* Just call the parent handler. This assumes that there is a variable
59
* named parent_class that points to the (duh!) parent class. Note that
60
* this macro is not to be used with things that return something, use
61
* the _WITH_DEFAULT version for that */
62
#define EGG_CALL_PARENT(parent_class_cast, name, args) \
63
((parent_class_cast(parent_class)->name != NULL) ? \
64
parent_class_cast(parent_class)->name args : (void)0)
66
/* Same as above, but in case there is no implementation, it evaluates
68
#define EGG_CALL_PARENT_WITH_DEFAULT(parent_class_cast, \
69
name, args, def_return) \
70
((parent_class_cast(parent_class)->name != NULL) ? \
71
parent_class_cast(parent_class)->name args : def_return)
73
/* Call a virtual method */
74
#define EGG_CALL_VIRTUAL(object, get_class_cast, method, args) \
75
(get_class_cast (object)->method ? (* get_class_cast (object)->method) args : (void)0)
77
/* Call a virtual method with default */
78
#define EGG_CALL_VIRTUAL_WITH_DEFAULT(object, get_class_cast, method, args, default) \
79
(get_class_cast (object)->method ? (* get_class_cast (object)->method) args : default)
81
#define EGG_CLASS_BOILERPLATE(type, type_as_function, \
82
parent_type, parent_type_macro) \
83
EGG_BOILERPLATE(type, type_as_function, type, \
84
parent_type, parent_type_macro, \
87
#define EGG_REGISTER_TYPE(type, type_as_function, corba_type, \
88
parent_type, parent_type_macro) \
89
g_type_register_static (parent_type_macro, #type, &object_info, 0)
92
#define EGG_DEFINE_BOXED_TYPE(TN, t_n) \
93
EGG_DEFINE_BOXED_TYPE_WITH_CODE(TN, t_n, {});
95
#define EGG_DEFINE_BOXED_TYPE_WITH_CODE(TN, t_n, _C_) \
97
static gpointer t_n##_copy (gpointer boxed); \
98
static void t_n##_free (gpointer boxed); \
100
EGG_DEFINE_BOXED_TYPE_EXTENDED(TN, t_n, t_n##_copy, t_n##_free, _C_);
102
#define EGG_DEFINE_BOXED_TYPE_EXTENDED(TN, t_n, b_c, b_f, _C_) \
104
_EGG_DEFINE_BOXED_TYPE_EXTENDED_BEGIN(TN, t_n, b_c, b_f) {_C_;} \
105
_EGG_DEFINE_BOXED_TYPE_EXTENDED_END()
107
#define _EGG_DEFINE_BOXED_TYPE_EXTENDED_BEGIN(TypeName, type_name, boxed_copy, boxed_free) \
110
type_name##_get_type (void) \
112
static volatile gsize g_define_type_id__volatile = 0; \
113
if (g_once_init_enter (&g_define_type_id__volatile)) \
115
GType g_define_type_id = \
116
g_boxed_type_register_static (g_intern_static_string (#TypeName), \
117
boxed_copy, boxed_free); \
118
{ /* custom code follows */
119
#define _EGG_DEFINE_BOXED_TYPE_EXTENDED_END() \
120
/* following custom code */ \
122
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
124
return g_define_type_id__volatile; \
125
} /* closes type_name##_get_type() */
127
#define EGG_DEFINE_QUARK(QN, q_n) \
132
static volatile gsize g_define_quark__volatile = 0; \
133
if (g_once_init_enter (&g_define_quark__volatile)) \
135
GQuark g_define_quark = g_quark_from_string (#QN); \
136
g_once_init_leave (&g_define_quark__volatile, g_define_quark); \
138
return g_define_quark__volatile; \
141
#define EGG_IS_POSITIVE_RESPONSE(response_id) \
142
((response_id) == GTK_RESPONSE_ACCEPT || \
143
(response_id) == GTK_RESPONSE_OK || \
144
(response_id) == GTK_RESPONSE_YES || \
145
(response_id) == GTK_RESPONSE_APPLY)
147
#define EGG_IS_NEGATIVE_RESPONSE(response_id) \
148
((response_id) == GTK_RESPONSE_REJECT || \
149
(response_id) == GTK_RESPONSE_CANCEL || \
150
(response_id) == GTK_RESPONSE_NO)
154
#endif /* _EGG_MACROS_H_ */