]> git.saurik.com Git - wxWidgets.git/blob - include/wx/xti2.h
props
[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 class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject
22 {
23 friend class WXDLLIMPEXP_FWD_BASE wxDynamicClassInfo ;
24 public:
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 }
47 private :
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"
61
62 // ----------------------------------------------------------------------------
63 // wxIMPLEMENT class macros for concrete classes
64 // ----------------------------------------------------------------------------
65
66 // Single inheritance with one base class
67
68 #define _DEFAULT_CONSTRUCTOR(name) \
69 wxObject* wxConstructorFor##name() \
70 { return new name; }
71
72 #define _DEFAULT_CONVERTERS(name) \
73 wxObject* wxVariantOfPtrToObjectConverter##name ( const wxAny &data ) \
74 { return data.As( (name**)NULL ); } \
75 wxAny wxObjectToVariantConverter##name ( wxObject *data ) \
76 { return wxAny( wx_dynamic_cast(name*, data) ); }
77
78 #define _TYPEINFO_CLASSES(n, toString, fromString ) \
79 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT, &n::ms_classInfo, \
80 toString, fromString, typeid(n).name()); \
81 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR, &n::ms_classInfo, \
82 toString, fromString, typeid(n*).name());
83
84 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit, callback) \
85 _DEFAULT_CONSTRUCTOR(name) \
86 _DEFAULT_CONVERTERS(name) \
87 \
88 const wxClassInfo* name::ms_classParents[] = \
89 { &basename::ms_classInfo, NULL }; \
90 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
91 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
92 name::GetPropertiesStatic, name::GetHandlersStatic, name::ms_constructor, \
93 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
94 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
95 callback);
96
97 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
98 _DEFAULT_CONSTRUCTOR(name) \
99 _DEFAULT_CONVERTERS(name) \
100 void wxVariantToObjectConverter##name ( const wxAny &data, wxObjectFunctor* fn ) \
101 { (*fn)( &wxANY_AS(data, name) ); } \
102 \
103 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo,NULL }; \
104 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
105 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
106 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
107 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
108 wxVariantOfPtrToObjectConverter##name, wxVariantToObjectConverter##name, \
109 wxObjectToVariantConverter##name, callback);
110
111 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename ) \
112 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, "", NULL ) \
113 _TYPEINFO_CLASSES(name, NULL, NULL) \
114 const wxPropertyInfo *name::GetPropertiesStatic() \
115 { return (wxPropertyInfo*) NULL; } \
116 const wxHandlerInfo *name::GetHandlersStatic() \
117 { return (wxHandlerInfo*) NULL; } \
118 wxCONSTRUCTOR_DUMMY( name )
119
120 #define wxIMPLEMENT_DYNAMIC_CLASS( name, basename ) \
121 _IMPLEMENT_DYNAMIC_CLASS( name, basename, "", NULL ) \
122 _TYPEINFO_CLASSES(name, NULL, NULL) \
123 wxPropertyInfo *name::GetPropertiesStatic() \
124 { return (wxPropertyInfo*) NULL; } \
125 wxHandlerInfo *name::GetHandlersStatic() \
126 { return (wxHandlerInfo*) NULL; } \
127 wxCONSTRUCTOR_DUMMY( name )
128
129 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \
130 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, NULL ) \
131 _TYPEINFO_CLASSES(name, NULL, NULL)
132
133 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback )\
134 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, &callback ) \
135 _TYPEINFO_CLASSES(name, NULL, NULL)
136
137 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \
138 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
139 _TYPEINFO_CLASSES(name, NULL, NULL)
140
141 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
142 unit, toString, \
143 fromString ) \
144 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
145 _TYPEINFO_CLASSES(name, toString, fromString)
146
147 // this is for classes that do not derive from wxObject, there are no creators for these
148
149 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) \
150 const wxClassInfo* name::ms_classParents[] = { NULL }; \
151 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
152 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
153 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
154 0, 0, 0 ); \
155 _TYPEINFO_CLASSES(name, NULL, NULL)
156
157 // this is for subclasses that still do not derive from wxObject
158
159 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) \
160 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo, NULL }; \
161 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
162 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
163 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
164 0, 0, 0 ); \
165 _TYPEINFO_CLASSES(name, NULL, NULL)
166
167
168 // Multiple inheritance with two base classes
169
170 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \
171 _DEFAULT_CONSTRUCTOR(name) \
172 _DEFAULT_CONVERTERS(name) \
173 \
174 const wxClassInfo* name::ms_classParents[] = \
175 { &basename::ms_classInfo,&basename2::ms_classInfo, NULL }; \
176 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
177 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
178 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
179 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
180 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
181 callback);
182
183 #define wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2) \
184 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, "", NULL) \
185 _TYPEINFO_CLASSES(name, NULL, NULL) \
186 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; } \
187 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
188 wxCONSTRUCTOR_DUMMY( name )
189
190 #define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) \
191 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, unit, NULL) \
192 _TYPEINFO_CLASSES(name, NULL, NULL)
193
194
195
196 // ----------------------------------------------------------------------------
197 // wxIMPLEMENT class macros for abstract classes
198 // ----------------------------------------------------------------------------
199
200 // Single inheritance with one base class
201
202 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
203 _DEFAULT_CONVERTERS(name) \
204 \
205 const wxClassInfo* name::ms_classParents[] = \
206 { &basename::ms_classInfo,NULL }; \
207 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
208 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
209 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
210 0, wxVariantOfPtrToObjectConverter##name,0, \
211 wxObjectToVariantConverter##name); \
212 _TYPEINFO_CLASSES(name, NULL, NULL)
213
214 #define wxIMPLEMENT_ABSTRACT_CLASS( name, basename ) \
215 _IMPLEMENT_ABSTRACT_CLASS( name, basename ) \
216 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
217 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; }
218
219 // Multiple inheritance with two base classes
220
221 #define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
222 wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
223 wxT(#basename2), (int) sizeof(name), \
224 (wxObjectConstructorFn) 0);
225
226 // templated streaming, every type must have their specialization for these methods
227
228 template<typename T>
229 void wxStringReadValue( const wxString &s, T &data );
230
231 template<typename T>
232 void wxStringWriteValue( wxString &s, const T &data);
233
234 template<typename T>
235 void wxToStringConverter( const wxAny &v, wxString &s )
236 { wxStringWriteValue(s, wxANY_AS(v, T)); }
237
238 template<typename T>
239 void wxFromStringConverter( const wxString &s, wxAny &v)
240 { T d; wxStringReadValue(s, d); v = wxAny(d); }
241
242 #endif
243
244 #endif // _WX_XTIH2__