]> git.saurik.com Git - wxWidgets.git/blob - include/wx/xti2.h
fix wxBitmapComboBox Gtk-CRITICAL assertion `GTK_IS_ENTRY (entry)' failed
[wxWidgets.git] / include / wx / xti2.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/wxt2.h
3 // Purpose: runtime metadata information (extended class info)
4 // Author: Stefan Csomor
5 // Modified by: Francesco Montorsi
6 // Created: 27/07/03
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_XTI2H__
13 #define _WX_XTI2H__
14
15 // ----------------------------------------------------------------------------
16 // second part of xti headers, is included from object.h
17 // ----------------------------------------------------------------------------
18
19 #if wxUSE_EXTENDED_RTTI
20
21 // ----------------------------------------------------------------------------
22 // wxDynamicObject class, its instances connect to a 'super class instance'
23 // ----------------------------------------------------------------------------
24
25 class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject
26 {
27 friend class WXDLLIMPEXP_FWD_BASE wxDynamicClassInfo ;
28 public:
29 // instantiates this object with an instance of its superclass
30 wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ;
31 virtual ~wxDynamicObject();
32
33 void SetProperty (const wxChar *propertyName, const wxAny &value);
34 wxAny GetProperty (const wxChar *propertyName) const ;
35
36 // get the runtime identity of this object
37 wxClassInfo *GetClassInfo() const
38 {
39 #ifdef _MSC_VER
40 return (wxClassInfo*) m_classInfo;
41 #else
42 wxDynamicClassInfo *nonconst = const_cast<wxDynamicClassInfo *>(m_classInfo);
43 return static_cast<wxClassInfo *>(nonconst);
44 #endif
45 }
46
47 wxObject* GetSuperClassInstance() const
48 {
49 return m_superClassInstance ;
50 }
51 private :
52 // removes an existing runtime-property
53 void RemoveProperty( const wxChar *propertyName ) ;
54
55 // renames an existing runtime-property
56 void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ;
57
58 wxObject *m_superClassInstance ;
59 const wxDynamicClassInfo *m_classInfo;
60 struct wxDynamicObjectInternal;
61 wxDynamicObjectInternal *m_data;
62 };
63
64 // ----------------------------------------------------------------------------
65 // String conversion templates supporting older compilers
66 // ----------------------------------------------------------------------------
67
68 #if wxUSE_FUNC_TEMPLATE_POINTER
69 # define wxTO_STRING(type) wxToStringConverter<type>
70 # define wxTO_STRING_IMP(type)
71 # define wxFROM_STRING(type) wxFromStringConverter<type>
72 # define wxFROM_STRING_IMP(type)
73 #else
74 # define wxTO_STRING(type) ToString##type
75 # define wxTO_STRING_IMP(type) \
76 inline void ToString##type( const wxAny& data, wxString &result ) \
77 { wxToStringConverter<type>(data, result); }
78
79 # define wxFROM_STRING(type) FromString##type
80 # define wxFROM_STRING_IMP(type) \
81 inline void FromString##type( const wxString& data, wxAny &result ) \
82 { wxFromStringConverter<type>(data, result); }
83 #endif
84
85 #include "wx/xtiprop.h"
86 #include "wx/xtictor.h"
87
88 // ----------------------------------------------------------------------------
89 // wxIMPLEMENT class macros for concrete classes
90 // ----------------------------------------------------------------------------
91
92 // Single inheritance with one base class
93
94 #define _DEFAULT_CONSTRUCTOR(name) \
95 wxObject* wxConstructorFor##name() \
96 { return new name; }
97
98 #define _DEFAULT_CONVERTERS(name) \
99 wxObject* wxVariantOfPtrToObjectConverter##name ( const wxAny &data ) \
100 { return data.As( (name**)NULL ); } \
101 wxAny wxObjectToVariantConverter##name ( wxObject *data ) \
102 { return wxAny( wx_dynamic_cast(name*, data) ); }
103
104 #define _TYPEINFO_CLASSES(n, toString, fromString ) \
105 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT, &n::ms_classInfo, \
106 toString, fromString, typeid(n).name()); \
107 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR, &n::ms_classInfo, \
108 toString, fromString, typeid(n*).name());
109
110 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit, callback) \
111 _DEFAULT_CONSTRUCTOR(name) \
112 _DEFAULT_CONVERTERS(name) \
113 \
114 const wxClassInfo* name::ms_classParents[] = \
115 { &basename::ms_classInfo, NULL }; \
116 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
117 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
118 name::GetPropertiesStatic, name::GetHandlersStatic, name::ms_constructor, \
119 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
120 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
121 callback);
122
123 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
124 _DEFAULT_CONSTRUCTOR(name) \
125 _DEFAULT_CONVERTERS(name) \
126 void wxVariantToObjectConverter##name ( const wxAny &data, wxObjectFunctor* fn ) \
127 { name o = wxANY_AS(data, name); (*fn)( &o ); } \
128 \
129 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo,NULL }; \
130 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
131 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
132 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
133 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
134 wxVariantOfPtrToObjectConverter##name, wxVariantToObjectConverter##name, \
135 wxObjectToVariantConverter##name, callback);
136
137 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename ) \
138 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, "", NULL ) \
139 _TYPEINFO_CLASSES(name, NULL, NULL) \
140 const wxPropertyInfo *name::GetPropertiesStatic() \
141 { return (wxPropertyInfo*) NULL; } \
142 const wxHandlerInfo *name::GetHandlersStatic() \
143 { return (wxHandlerInfo*) NULL; } \
144 wxCONSTRUCTOR_DUMMY( name )
145
146 #define wxIMPLEMENT_DYNAMIC_CLASS( name, basename ) \
147 _IMPLEMENT_DYNAMIC_CLASS( name, basename, "", NULL ) \
148 _TYPEINFO_CLASSES(name, NULL, NULL) \
149 wxPropertyInfo *name::GetPropertiesStatic() \
150 { return (wxPropertyInfo*) NULL; } \
151 wxHandlerInfo *name::GetHandlersStatic() \
152 { return (wxHandlerInfo*) NULL; } \
153 wxCONSTRUCTOR_DUMMY( name )
154
155 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \
156 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, NULL ) \
157 _TYPEINFO_CLASSES(name, NULL, NULL)
158
159 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback )\
160 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, &callback ) \
161 _TYPEINFO_CLASSES(name, NULL, NULL)
162
163 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \
164 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
165 _TYPEINFO_CLASSES(name, NULL, NULL)
166
167 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
168 unit, toString, \
169 fromString ) \
170 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
171 _TYPEINFO_CLASSES(name, toString, fromString)
172
173 // this is for classes that do not derive from wxObject, there are no creators for these
174
175 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) \
176 const wxClassInfo* name::ms_classParents[] = { NULL }; \
177 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
178 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
179 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
180 0, 0, 0 ); \
181 _TYPEINFO_CLASSES(name, NULL, NULL)
182
183 // this is for subclasses that still do not derive from wxObject
184
185 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) \
186 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo, NULL }; \
187 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
188 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
189 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
190 0, 0, 0 ); \
191 _TYPEINFO_CLASSES(name, NULL, NULL)
192
193
194 // Multiple inheritance with two base classes
195
196 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \
197 _DEFAULT_CONSTRUCTOR(name) \
198 _DEFAULT_CONVERTERS(name) \
199 \
200 const wxClassInfo* name::ms_classParents[] = \
201 { &basename::ms_classInfo,&basename2::ms_classInfo, NULL }; \
202 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
203 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
204 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
205 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
206 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
207 callback);
208
209 #define wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2) \
210 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, "", NULL) \
211 _TYPEINFO_CLASSES(name, NULL, NULL) \
212 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; } \
213 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
214 wxCONSTRUCTOR_DUMMY( name )
215
216 #define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) \
217 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, unit, NULL) \
218 _TYPEINFO_CLASSES(name, NULL, NULL)
219
220
221
222 // ----------------------------------------------------------------------------
223 // wxIMPLEMENT class macros for abstract classes
224 // ----------------------------------------------------------------------------
225
226 // Single inheritance with one base class
227
228 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
229 _DEFAULT_CONVERTERS(name) \
230 \
231 const wxClassInfo* name::ms_classParents[] = \
232 { &basename::ms_classInfo,NULL }; \
233 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
234 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
235 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
236 0, wxVariantOfPtrToObjectConverter##name,0, \
237 wxObjectToVariantConverter##name); \
238 _TYPEINFO_CLASSES(name, NULL, NULL)
239
240 #define wxIMPLEMENT_ABSTRACT_CLASS( name, basename ) \
241 _IMPLEMENT_ABSTRACT_CLASS( name, basename ) \
242 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
243 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; }
244
245 // Multiple inheritance with two base classes
246
247 #define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
248 wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
249 wxT(#basename2), (int) sizeof(name), \
250 (wxObjectConstructorFn) 0);
251
252 // templated streaming, every type that can be converted to wxString
253 // must have their specialization for these methods
254
255 template<typename T>
256 void wxStringReadValue( const wxString &s, T &data );
257
258 template<typename T>
259 void wxStringWriteValue( wxString &s, const T &data);
260
261 template<typename T>
262 void wxToStringConverter( const wxAny &v, wxString &s )
263 { wxStringWriteValue(s, wxANY_AS(v, T)); }
264
265 template<typename T>
266 void wxFromStringConverter( const wxString &s, wxAny &v)
267 { T d; wxStringReadValue(s, d); v = wxAny(d); }
268
269 // --------------------------------------------------------------------------
270 // Collection Support
271 // --------------------------------------------------------------------------
272
273 template<typename iter, typename collection_t > void wxListCollectionToAnyList(
274 const collection_t& coll, wxAnyList &value )
275 {
276 for ( iter current = coll.GetFirst(); current;
277 current = current->GetNext() )
278 {
279 value.Append( new wxAny(current->GetData()) );
280 }
281 }
282
283 template<typename collection_t> void wxArrayCollectionToVariantArray(
284 const collection_t& coll, wxAnyList &value )
285 {
286 for( size_t i = 0; i < coll.GetCount(); i++ )
287 {
288 value.Append( new wxAny(coll[i]) );
289 }
290 }
291
292 #endif
293
294 #endif // _WX_XTIH2__