]> git.saurik.com Git - wxWidgets.git/blame - include/wx/xti2.h
update docs after r66615
[wxWidgets.git] / include / wx / xti2.h
CommitLineData
aa3fcb2f
SC
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
21class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject
22{
23 friend class WXDLLIMPEXP_FWD_BASE wxDynamicClassInfo ;
24public:
25 // instantiates this object with an instance of its superclass
26 wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ;
27 virtual ~wxDynamicObject();
28
29 void SetProperty (const wxChar *propertyName, const wxAny &value);
30 wxAny GetProperty (const wxChar *propertyName) const ;
31
32 // get the runtime identity of this object
33 wxClassInfo *GetClassInfo() const
34 {
35#ifdef _MSC_VER
36 return (wxClassInfo*) m_classInfo;
37#else
38 wxDynamicClassInfo *nonconst = const_cast<wxDynamicClassInfo *>(m_classInfo);
39 return static_cast<wxClassInfo *>(nonconst);
40#endif
41 }
42
43 wxObject* GetSuperClassInstance() const
44 {
45 return m_superClassInstance ;
46 }
47private :
48 // removes an existing runtime-property
49 void RemoveProperty( const wxChar *propertyName ) ;
50
51 // renames an existing runtime-property
52 void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ;
53
54 wxObject *m_superClassInstance ;
55 const wxDynamicClassInfo *m_classInfo;
56 struct wxDynamicObjectInternal;
57 wxDynamicObjectInternal *m_data;
58};
59
60#include "wx/xtiprop.h"
bca6bd38 61#include "wx/xtictor.h"
aa3fcb2f
SC
62
63// ----------------------------------------------------------------------------
64// wxIMPLEMENT class macros for concrete classes
65// ----------------------------------------------------------------------------
66
67// Single inheritance with one base class
68
69#define _DEFAULT_CONSTRUCTOR(name) \
70wxObject* wxConstructorFor##name() \
71{ return new name; }
72
73#define _DEFAULT_CONVERTERS(name) \
74wxObject* wxVariantOfPtrToObjectConverter##name ( const wxAny &data ) \
75{ return data.As( (name**)NULL ); } \
76 wxAny wxObjectToVariantConverter##name ( wxObject *data ) \
77{ return wxAny( wx_dynamic_cast(name*, data) ); }
78
79#define _TYPEINFO_CLASSES(n, toString, fromString ) \
80 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT, &n::ms_classInfo, \
81 toString, fromString, typeid(n).name()); \
82 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR, &n::ms_classInfo, \
83 toString, fromString, typeid(n*).name());
84
85#define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit, callback) \
86 _DEFAULT_CONSTRUCTOR(name) \
87 _DEFAULT_CONVERTERS(name) \
88 \
89 const wxClassInfo* name::ms_classParents[] = \
90{ &basename::ms_classInfo, NULL }; \
91 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
92 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
93 name::GetPropertiesStatic, name::GetHandlersStatic, name::ms_constructor, \
94 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
95 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
96 callback);
97
98#define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
99 _DEFAULT_CONSTRUCTOR(name) \
100 _DEFAULT_CONVERTERS(name) \
101 void wxVariantToObjectConverter##name ( const wxAny &data, wxObjectFunctor* fn ) \
102{ (*fn)( &wxANY_AS(data, name) ); } \
103 \
104 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo,NULL }; \
105 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
106 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
107 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
108 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
109 wxVariantOfPtrToObjectConverter##name, wxVariantToObjectConverter##name, \
110 wxObjectToVariantConverter##name, callback);
111
112#define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename ) \
113 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, "", NULL ) \
114 _TYPEINFO_CLASSES(name, NULL, NULL) \
115 const wxPropertyInfo *name::GetPropertiesStatic() \
116{ return (wxPropertyInfo*) NULL; } \
117 const wxHandlerInfo *name::GetHandlersStatic() \
118{ return (wxHandlerInfo*) NULL; } \
119 wxCONSTRUCTOR_DUMMY( name )
120
121#define wxIMPLEMENT_DYNAMIC_CLASS( name, basename ) \
122 _IMPLEMENT_DYNAMIC_CLASS( name, basename, "", NULL ) \
123 _TYPEINFO_CLASSES(name, NULL, NULL) \
124 wxPropertyInfo *name::GetPropertiesStatic() \
125{ return (wxPropertyInfo*) NULL; } \
126 wxHandlerInfo *name::GetHandlersStatic() \
127{ return (wxHandlerInfo*) NULL; } \
128 wxCONSTRUCTOR_DUMMY( name )
129
130#define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \
131 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, NULL ) \
132 _TYPEINFO_CLASSES(name, NULL, NULL)
133
134#define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback )\
135 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, &callback ) \
136 _TYPEINFO_CLASSES(name, NULL, NULL)
137
138#define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \
139 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
140 _TYPEINFO_CLASSES(name, NULL, NULL)
141
142#define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
143 unit, toString, \
144 fromString ) \
145 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
146 _TYPEINFO_CLASSES(name, toString, fromString)
147
148// this is for classes that do not derive from wxObject, there are no creators for these
149
150#define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) \
151 const wxClassInfo* name::ms_classParents[] = { NULL }; \
152 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
153 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
154 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
155 0, 0, 0 ); \
156 _TYPEINFO_CLASSES(name, NULL, NULL)
157
158// this is for subclasses that still do not derive from wxObject
159
160#define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) \
161 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo, NULL }; \
162 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
163 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
164 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
165 0, 0, 0 ); \
166 _TYPEINFO_CLASSES(name, NULL, NULL)
167
168
169// Multiple inheritance with two base classes
170
171#define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \
172 _DEFAULT_CONSTRUCTOR(name) \
173 _DEFAULT_CONVERTERS(name) \
174 \
175 const wxClassInfo* name::ms_classParents[] = \
176{ &basename::ms_classInfo,&basename2::ms_classInfo, NULL }; \
177 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
178 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
179 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
180 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
181 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
182 callback);
183
184#define wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2) \
185 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, "", NULL) \
186 _TYPEINFO_CLASSES(name, NULL, NULL) \
187 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; } \
188 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
189 wxCONSTRUCTOR_DUMMY( name )
190
191#define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) \
192 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, unit, NULL) \
193 _TYPEINFO_CLASSES(name, NULL, NULL)
194
195
196
197// ----------------------------------------------------------------------------
198// wxIMPLEMENT class macros for abstract classes
199// ----------------------------------------------------------------------------
200
201// Single inheritance with one base class
202
203#define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
204 _DEFAULT_CONVERTERS(name) \
205 \
206 const wxClassInfo* name::ms_classParents[] = \
207{ &basename::ms_classInfo,NULL }; \
208 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
209 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
210 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
211 0, wxVariantOfPtrToObjectConverter##name,0, \
212 wxObjectToVariantConverter##name); \
213 _TYPEINFO_CLASSES(name, NULL, NULL)
214
215#define wxIMPLEMENT_ABSTRACT_CLASS( name, basename ) \
216 _IMPLEMENT_ABSTRACT_CLASS( name, basename ) \
217 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
218 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; }
219
220// Multiple inheritance with two base classes
221
222#define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
223 wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
224 wxT(#basename2), (int) sizeof(name), \
225 (wxObjectConstructorFn) 0);
226
227// templated streaming, every type must have their specialization for these methods
228
229template<typename T>
230void wxStringReadValue( const wxString &s, T &data );
231
232template<typename T>
233void wxStringWriteValue( wxString &s, const T &data);
234
235template<typename T>
236void wxToStringConverter( const wxAny &v, wxString &s )
237{ wxStringWriteValue(s, wxANY_AS(v, T)); }
238
239template<typename T>
240void wxFromStringConverter( const wxString &s, wxAny &v)
241{ T d; wxStringReadValue(s, d); v = wxAny(d); }
242
bca6bd38
SC
243// --------------------------------------------------------------------------
244// Collection Support
245// --------------------------------------------------------------------------
246
247template<typename iter, typename collection_t > void wxListCollectionToAnyList(
248 const collection_t& coll, wxAnyList &value )
249{
250 for ( iter current = coll.GetFirst(); current;
251 current = current->GetNext() )
252 {
253 value.Append( new wxAny(current->GetData()) );
254 }
255}
256
257template<typename collection_t> void wxArrayCollectionToVariantArray(
258 const collection_t& coll, wxAnyList &value )
259{
260 for( size_t i = 0; i < coll.GetCount(); i++ )
261 {
262 value.Append( new wxAny(coll[i]) );
263 }
264}
265
aa3fcb2f
SC
266#endif
267
268#endif // _WX_XTIH2__