add new sigc++2 directory
[ardour.git] / libs / glibmm2 / tools / m4 / class_gobject.m4
1 dnl $Id: class_gobject.m4 413 2007-05-14 19:28:31Z murrayc $
2
3
4 define(`_CLASS_GOBJECT',`dnl
5 _PUSH()
6 dnl
7 dnl  Define the args for later macros
8 define(`__CPPNAME__',`$1')
9 define(`__CNAME__',`$2')
10 define(`__CCAST__',`$3')
11 define(`__BASE__',_LOWER(__CPPNAME__))
12 define(`__CPPPARENT__',`$4')
13 define(`__CPARENT__',`$5')
14 define(`__PCAST__',`($5*)')
15
16 dnl Some C types, e.g. GdkWindow or GdkPixmap, are a typedef to their base type,
17 dnl rather than the real instance type.  That is really ugly, yes.  We get around
18 dnl the problem by supporting optional __REAL_* arguments to this macro.
19 define(`__REAL_CNAME__',ifelse(`$6',,__CNAME__,`$6'))
20 define(`__REAL_CPARENT__',ifelse(`$7',,__CPARENT__,`$7'))
21
22
23 _POP()
24 _SECTION(SECTION_CLASS2)
25 ') dnl end of _CLASS_GOBJECT
26
27 dnl Widget and Object, and some others, have custom-written destructor implementations:
28 define(`_CUSTOM_DTOR',`dnl
29 _PUSH()
30 dnl Define this macro to be tested for later.
31 define(`__BOOL_CUSTOM_DTOR__',`$1')
32 _POP()
33 ')
34
35 dnl Gdk::Pixmap_Class::wrap_new() needs a custom implementation, in order
36 dnl to create a Gdk::Bitmap object if appropriate.  See comments there.
37 define(`_CUSTOM_WRAP_NEW',`dnl
38 _PUSH()
39 dnl Define this macro to be tested for later.
40 define(`__BOOL_CUSTOM_WRAP_NEW__',`1')
41 _POP()
42 ')
43
44 dnl Gnome::Canvas::CanvasAA::CanvasAA() needs access to the
45 dnl normally-private canvas_class_ member variable. See comments there.
46 define(`_GMMPROC_PROTECTED_GCLASS',`dnl
47 _PUSH()
48 dnl Define this macro to be tested for later.
49 define(`__BOOL_PROTECTED_GCLASS__',`1')
50 _POP()
51 ')
52
53 dnl Some of the Gdk types are actually direct typedefs of their base type.
54 dnl This means that 2 wrap functions would have the same argument.
55 dnl define(`_NO_WRAP_FUNCTION',`dnl
56 dnl _PUSH()
57 dnl Define this macro to be tested for later.
58 dnl define(`__BOOL_NO_WRAP_FUNCTION__',`$1')
59 dnl _POP()
60 dnl ')
61
62 dnl
63 dnl _CREATE_METHOD(args_type_and_name_hpp, args_type_and_name_cpp,args_name_only);
64 dnl
65 define(`_CREATE_METHOD',`
66   static Glib::RefPtr<`'__CPPNAME__`'> create(`'$1`');
67 _PUSH(SECTION_CC)
68 Glib::RefPtr<`'__CPPNAME__`'> __CPPNAME__`'::create(`'$2`')
69 {
70   return Glib::RefPtr<`'__CPPNAME__`'>( new __CPPNAME__`'(`'$3`') );
71 }
72 _POP()
73 ')
74
75
76 dnl
77 dnl _END_CLASS_GOBJECT()
78 dnl   denotes the end of a class
79 dnl
80 define(`_END_CLASS_GOBJECT',`
81 _SECTION(SECTION_HEADER1)
82 ifdef(`__BOOL_NO_WRAP_FUNCTION__',`dnl
83 ',`dnl
84 _STRUCT_PROTOTYPE()
85 ')dnl
86
87 __NAMESPACE_BEGIN__ class __CPPNAME__`'_Class; __NAMESPACE_END__
88 _SECTION(SECTION_HEADER3)
89
90 ifdef(`__BOOL_NO_WRAP_FUNCTION__',`dnl
91 ',`dnl
92 namespace Glib
93 {
94   /** A Glib::wrap() method for this object.
95    * 
96    * @param object The C instance.
97    * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
98    * @result A C++ instance that wraps this C instance.
99    *
100    * @relates __NAMESPACE__::__CPPNAME__
101    */
102   Glib::RefPtr<__NAMESPACE__::__CPPNAME__> wrap(__REAL_CNAME__`'* object, bool take_copy = false);
103 }
104 ')dnl
105
106
107 dnl
108 dnl
109 _SECTION(SECTION_PHEADER)
110
111 #include <glibmm/class.h>
112
113 __NAMESPACE_BEGIN__
114
115 _PH_CLASS_DECLARATION()
116
117 __NAMESPACE_END__
118
119 _SECTION(SECTION_SRC_GENERATED)
120
121 ifdef(`__BOOL_NO_WRAP_FUNCTION__',`dnl
122 ',`dnl else
123 namespace Glib
124 {
125
126 Glib::RefPtr<__NAMESPACE__::__CPPNAME__> wrap(__REAL_CNAME__`'* object, bool take_copy)
127 {
128   return Glib::RefPtr<__NAMESPACE__::__CPPNAME__>( dynamic_cast<__NAMESPACE__::__CPPNAME__*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
129   //We use dynamic_cast<> in case of multiple inheritance.
130 }
131
132 } /* namespace Glib */
133 ')dnl endif
134
135
136
137
138 __NAMESPACE_BEGIN__
139
140
141 /* The *_Class implementation: */
142
143 _PCC_CLASS_IMPLEMENTATION()
144
145 m4_ifdef(`__BOOL_CUSTOM_WRAP_NEW__',,`dnl else
146 Glib::ObjectBase* __CPPNAME__`'_Class::wrap_new(GObject* object)
147 {
148   return new __CPPNAME__`'((__CNAME__*)`'object);
149 }
150
151 ')dnl endif
152
153 /* The implementation: */
154
155 __CNAME__* __CPPNAME__::gobj_copy()
156 {
157   reference();
158   return gobj();
159 }
160
161 __CPPNAME__::__CPPNAME__`'(const Glib::ConstructParams& construct_params)
162 :
163   __CPPPARENT__`'(construct_params)
164 {}
165
166 __CPPNAME__::__CPPNAME__`'(__CNAME__* castitem)
167 :
168   __CPPPARENT__`'(__PCAST__`'(castitem))
169 {}
170
171 ifdef(`__BOOL_CUSTOM_DTOR__',`dnl
172 ',`dnl
173 __CPPNAME__::~__CPPNAME__`'()
174 {}
175
176 ')dnl
177
178
179 _CC_CLASS_IMPLEMENTATION()
180
181 __NAMESPACE_END__
182
183 dnl
184 dnl
185 dnl
186 dnl
187 _POP()
188 dnl
189 dnl The actual class, e.g. Gtk::Widget, declaration:
190 dnl _IMPORT(SECTION_H_SIGNALPROXIES_CUSTOM)
191
192 _IMPORT(SECTION_CLASS1)
193
194 #ifndef DOXYGEN_SHOULD_SKIP_THIS
195
196 public:
197   typedef __CPPNAME__ CppObjectType;
198   typedef __CPPNAME__`'_Class CppClassType;
199   typedef __CNAME__ BaseObjectType;
200   typedef __REAL_CNAME__`'Class BaseClassType;
201
202 m4_ifdef(`__BOOL_PROTECTED_GCLASS__',
203 `protected:',`dnl else
204 private:')dnl endif
205   friend class __CPPNAME__`'_Class;
206   static CppClassType `'__BASE__`'_class_;
207
208 private:
209   // noncopyable
210   __CPPNAME__`'(const __CPPNAME__&);
211   __CPPNAME__& operator=(const __CPPNAME__&);
212
213 protected:
214   explicit __CPPNAME__`'(const Glib::ConstructParams& construct_params);
215   explicit __CPPNAME__`'(__CNAME__* castitem);
216
217 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
218
219 public:
220   virtual ~__CPPNAME__`'();
221
222 #ifndef DOXYGEN_SHOULD_SKIP_THIS
223   static GType get_type()      G_GNUC_CONST;
224   static GType get_base_type() G_GNUC_CONST;
225 #endif
226
227   ///Provides access to the underlying C GObject.
228   __CNAME__*       gobj()       { return reinterpret_cast<__CNAME__*>(gobject_); }
229
230   ///Provides access to the underlying C GObject.
231   const __CNAME__* gobj() const { return reinterpret_cast<__CNAME__*>(gobject_); }
232
233   ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
234   __CNAME__* gobj_copy();
235
236 private:
237 _IMPORT(SECTION_CLASS2)
238
239 public:
240 _H_VFUNCS_AND_SIGNALS()
241
242 ')
243