]> www.fi.muni.cz Git - evince.git/blob - cut-n-paste/fileformatchooser/egg-macros.h
Allow exporting images in any format supported by GdkPixbuf. Fixes bug
[evince.git] / cut-n-paste / fileformatchooser / egg-macros.h
1 /**
2  * Useful macros.
3  *
4  * Author:
5  *   Darin Adler <darin@bentspoon.com>
6  *
7  * Copyright 2001 Ben Tea Spoons, Inc.
8  */
9 #ifndef _EGG_MACROS_H_
10 #define _EGG_MACROS_H_
11
12 #include <glib/gmacros.h>
13
14 G_BEGIN_DECLS
15
16 /* Macros for defining classes.  Ideas taken from Nautilus and GOB. */
17
18 /* Define the boilerplate type stuff to reduce typos and code size.  Defines
19  * the get_type method and the parent_class static variable. */
20
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;                       \
27 static void                                                             \
28 type_as_function ## _class_init_trampoline (gpointer klass,             \
29                                             gpointer data)              \
30 {                                                                       \
31         parent_class = (parent_type ## Class *)g_type_class_ref (       \
32                 parent_type_macro);                                     \
33         type_as_function ## _class_init ((type ## Class *)klass);       \
34 }                                                                       \
35 GType                                                                   \
36 type_as_function ## _get_type (void)                                    \
37 {                                                                       \
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 */                \
47                     sizeof (type),                                      \
48                     0,                  /* n_preallocs */               \
49                     (GInstanceInitFunc) type_as_function ## _instance_init \
50                 };                                                      \
51                 object_type = register_type_macro                       \
52                         (type, type_as_function, corba_type,            \
53                          parent_type, parent_type_macro);               \
54         }                                                               \
55         return object_type;                                             \
56 }
57
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)
65
66 /* Same as above, but in case there is no implementation, it evaluates
67  * to def_return */
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)
72
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)
76
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)
80
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,              \
85                            EGG_REGISTER_TYPE)
86
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)
90
91
92 #define EGG_DEFINE_BOXED_TYPE(TN, t_n) \
93 EGG_DEFINE_BOXED_TYPE_WITH_CODE(TN, t_n, {});
94
95 #define EGG_DEFINE_BOXED_TYPE_WITH_CODE(TN, t_n, _C_) \
96 \
97 static gpointer t_n##_copy (gpointer boxed); \
98 static void t_n##_free (gpointer boxed); \
99 \
100 EGG_DEFINE_BOXED_TYPE_EXTENDED(TN, t_n, t_n##_copy, t_n##_free, _C_);
101
102 #define EGG_DEFINE_BOXED_TYPE_EXTENDED(TN, t_n, b_c, b_f, _C_) \
103 \
104 _EGG_DEFINE_BOXED_TYPE_EXTENDED_BEGIN(TN, t_n, b_c, b_f) {_C_;} \
105 _EGG_DEFINE_BOXED_TYPE_EXTENDED_END()
106
107 #define _EGG_DEFINE_BOXED_TYPE_EXTENDED_BEGIN(TypeName, type_name, boxed_copy, boxed_free) \
108 \
109 GType \
110 type_name##_get_type (void) \
111 { \
112   static volatile gsize g_define_type_id__volatile = 0; \
113   if (g_once_init_enter (&g_define_type_id__volatile)) \
114     { \
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 */ \
121       } \
122       g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
123     } \
124   return g_define_type_id__volatile; \
125 } /* closes type_name##_get_type() */
126
127 #define EGG_DEFINE_QUARK(QN, q_n) \
128 \
129 GQuark \
130 q_n##_quark (void) \
131 { \
132   static volatile gsize g_define_quark__volatile = 0; \
133   if (g_once_init_enter (&g_define_quark__volatile)) \
134     { \
135       GQuark g_define_quark = g_quark_from_string (#QN); \
136       g_once_init_leave (&g_define_quark__volatile, g_define_quark); \
137     } \
138   return g_define_quark__volatile; \
139 }
140
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)
146
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)
151
152 G_END_DECLS
153
154 #endif /* _EGG_MACROS_H_ */