1 dnl $Id: class_gobject.m4 413 2007-05-14 19:28:31Z murrayc $
4 define(`_CLASS_GOBJECT',`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*)')
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'))
24 _SECTION(SECTION_CLASS2)
25 ') dnl end of _CLASS_GOBJECT
27 dnl Widget and Object, and some others, have custom-written destructor implementations:
28 define(`_CUSTOM_DTOR',`dnl
30 dnl Define this macro to be tested for later.
31 define(`__BOOL_CUSTOM_DTOR__',`$1')
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
39 dnl Define this macro to be tested for later.
40 define(`__BOOL_CUSTOM_WRAP_NEW__',`1')
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
48 dnl Define this macro to be tested for later.
49 define(`__BOOL_PROTECTED_GCLASS__',`1')
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
57 dnl Define this macro to be tested for later.
58 dnl define(`__BOOL_NO_WRAP_FUNCTION__',`$1')
63 dnl _CREATE_METHOD(args_type_and_name_hpp, args_type_and_name_cpp,args_name_only);
65 define(`_CREATE_METHOD',`
66 static Glib::RefPtr<`'__CPPNAME__`'> create(`'$1`');
68 Glib::RefPtr<`'__CPPNAME__`'> __CPPNAME__`'::create(`'$2`')
70 return Glib::RefPtr<`'__CPPNAME__`'>( new __CPPNAME__`'(`'$3`') );
77 dnl _END_CLASS_GOBJECT()
78 dnl denotes the end of a class
80 define(`_END_CLASS_GOBJECT',`
81 _SECTION(SECTION_HEADER1)
82 ifdef(`__BOOL_NO_WRAP_FUNCTION__',`dnl
87 __NAMESPACE_BEGIN__ class __CPPNAME__`'_Class; __NAMESPACE_END__
88 _SECTION(SECTION_HEADER3)
90 ifdef(`__BOOL_NO_WRAP_FUNCTION__',`dnl
94 /** A Glib::wrap() method for this object.
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.
100 * @relates __NAMESPACE__::__CPPNAME__
102 Glib::RefPtr<__NAMESPACE__::__CPPNAME__> wrap(__REAL_CNAME__`'* object, bool take_copy = false);
109 _SECTION(SECTION_PHEADER)
111 #include <glibmm/class.h>
115 _PH_CLASS_DECLARATION()
119 _SECTION(SECTION_SRC_GENERATED)
121 ifdef(`__BOOL_NO_WRAP_FUNCTION__',`dnl
126 Glib::RefPtr<__NAMESPACE__::__CPPNAME__> wrap(__REAL_CNAME__`'* object, bool take_copy)
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.
132 } /* namespace Glib */
141 /* The *_Class implementation: */
143 _PCC_CLASS_IMPLEMENTATION()
145 m4_ifdef(`__BOOL_CUSTOM_WRAP_NEW__',,`dnl else
146 Glib::ObjectBase* __CPPNAME__`'_Class::wrap_new(GObject* object)
148 return new __CPPNAME__`'((__CNAME__*)`'object);
153 /* The implementation: */
155 __CNAME__* __CPPNAME__::gobj_copy()
161 __CPPNAME__::__CPPNAME__`'(const Glib::ConstructParams& construct_params)
163 __CPPPARENT__`'(construct_params)
166 __CPPNAME__::__CPPNAME__`'(__CNAME__* castitem)
168 __CPPPARENT__`'(__PCAST__`'(castitem))
171 ifdef(`__BOOL_CUSTOM_DTOR__',`dnl
173 __CPPNAME__::~__CPPNAME__`'()
179 _CC_CLASS_IMPLEMENTATION()
189 dnl The actual class, e.g. Gtk::Widget, declaration:
190 dnl _IMPORT(SECTION_H_SIGNALPROXIES_CUSTOM)
192 _IMPORT(SECTION_CLASS1)
194 #ifndef DOXYGEN_SHOULD_SKIP_THIS
197 typedef __CPPNAME__ CppObjectType;
198 typedef __CPPNAME__`'_Class CppClassType;
199 typedef __CNAME__ BaseObjectType;
200 typedef __REAL_CNAME__`'Class BaseClassType;
202 m4_ifdef(`__BOOL_PROTECTED_GCLASS__',
203 `protected:',`dnl else
205 friend class __CPPNAME__`'_Class;
206 static CppClassType `'__BASE__`'_class_;
210 __CPPNAME__`'(const __CPPNAME__&);
211 __CPPNAME__& operator=(const __CPPNAME__&);
214 explicit __CPPNAME__`'(const Glib::ConstructParams& construct_params);
215 explicit __CPPNAME__`'(__CNAME__* castitem);
217 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
220 virtual ~__CPPNAME__`'();
222 #ifndef DOXYGEN_SHOULD_SKIP_THIS
223 static GType get_type() G_GNUC_CONST;
224 static GType get_base_type() G_GNUC_CONST;
227 ///Provides access to the underlying C GObject.
228 __CNAME__* gobj() { return reinterpret_cast<__CNAME__*>(gobject_); }
230 ///Provides access to the underlying C GObject.
231 const __CNAME__* gobj() const { return reinterpret_cast<__CNAME__*>(gobject_); }
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();
237 _IMPORT(SECTION_CLASS2)
240 _H_VFUNCS_AND_SIGNALS()