]> git.saurik.com Git - wxWidgets.git/blame - include/wx/xtiprop.h
gcc 4.3 issues warning if type attributes are given again - even if they are identica...
[wxWidgets.git] / include / wx / xtiprop.h
CommitLineData
e1d3601a
PC
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/xtiprop.h
3// Purpose: XTI properties
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// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef _XTIPROP_H_
14#define _XTIPROP_H_
15
16#include "wx/defs.h"
17
18#if wxUSE_EXTENDED_RTTI
19
6c887dde
SC
20#include "wx/xti.h"
21#include "wx/any.h"
e1d3601a 22
9ae4b67f 23/*
e1d3601a
PC
24class WXDLLIMPEXP_BASE wxObject;
25class WXDLLIMPEXP_BASE wxClassInfo;
26class WXDLLIMPEXP_BASE wxDynamicClassInfo;
9ae4b67f 27*/
e1d3601a
PC
28class WXDLLIMPEXP_BASE wxHashTable;
29class WXDLLIMPEXP_BASE wxHashTable_Node;
e1d3601a
PC
30class WXDLLIMPEXP_BASE wxEvent;
31class WXDLLIMPEXP_BASE wxEvtHandler;
32
33// ----------------------------------------------------------------------------
34// Property Accessors
35//
36// wxPropertySetter/Getter/CollectionGetter/CollectionAdder are all property
37// accessors which are managed by wxPropertyAccessor class which in turn is
38// handled by wxPropertyInfo.
39// ----------------------------------------------------------------------------
40
41class WXDLLIMPEXP_BASE wxPropertySetter
42{
43public:
44 wxPropertySetter( const wxString name ) { m_name = name; }
45 virtual ~wxPropertySetter() {}
46
6c887dde 47 virtual void Set( wxObject *object, const wxAny &variantValue ) const = 0;
e1d3601a
PC
48 const wxString& GetName() const { return m_name; }
49
50private:
51 wxString m_name;
52};
53
54class WXDLLIMPEXP_BASE wxPropertyGetter
55{
56public:
57 wxPropertyGetter( const wxString name ) { m_name = name; }
58 virtual ~wxPropertyGetter() {}
59
6c887dde 60 virtual void Get( const wxObject *object, wxAny& result) const = 0;
e1d3601a
PC
61 const wxString& GetName() const { return m_name; }
62
63private:
64 wxString m_name;
65};
66
67class WXDLLIMPEXP_BASE wxPropertyCollectionGetter
68{
69public:
70 wxPropertyCollectionGetter( const wxString name ) { m_name = name; }
71 virtual ~wxPropertyCollectionGetter() {}
72
6c887dde 73 virtual void Get( const wxObject *object, wxAnyList& result) const = 0;
e1d3601a
PC
74 const wxString& GetName() const { return m_name; }
75
76private:
77 wxString m_name;
78};
79
80template<typename coll_t> void WXDLLIMPEXP_BASE \
6c887dde 81 wxCollectionToVariantArray( const coll_t& coll, wxAnyList& result );
e1d3601a
PC
82
83class WXDLLIMPEXP_BASE wxPropertyCollectionAdder
84{
85public:
86 wxPropertyCollectionAdder( const wxString name ) { m_name = name; }
87 virtual ~wxPropertyCollectionAdder() {}
88
6c887dde 89 virtual void Add( wxObject *object, const wxAny &variantValue ) const= 0;
e1d3601a
PC
90 const wxString& GetName() const { return m_name; }
91
92private:
93 wxString m_name;
94};
95
6c887dde
SC
96#define wxPROPERTY_SETTER( property, Klass, valueType, setterMethod ) \
97class wxPropertySetter##property : public wxPropertySetter \
e1d3601a
PC
98{ \
99public: \
100 wxINFUNC_CLASS_TYPE_FIX(Klass) \
101 wxPropertySetter##property() : wxPropertySetter( wxT(#setterMethod) ) {} \
6c887dde 102 virtual ~wxPropertySetter##property() {} \
e1d3601a 103 \
6c887dde 104 void Set( wxObject *object, const wxAny &variantValue ) const \
e1d3601a 105 { \
6c887dde
SC
106 Klass *obj = dynamic_cast<Klass*>(object); \
107 valueType tempobj; \
108 if ( variantValue.GetAs(&tempobj) ) \
109 obj->setterMethod(tempobj); \
110 else \
111 obj->setterMethod(*wxANY_AS(variantValue, valueType*)); \
112 } \
e1d3601a
PC
113};
114
115#define wxPROPERTY_GETTER( property, Klass, valueType, gettermethod ) \
116class wxPropertyGetter##property : public wxPropertyGetter \
117{ \
118public: \
119 wxINFUNC_CLASS_TYPE_FIX(Klass) \
120 wxPropertyGetter##property() : wxPropertyGetter( wxT(#gettermethod) ) {} \
121 virtual ~wxPropertyGetter##property() {} \
122 \
6c887dde 123 void Get( const wxObject *object, wxAny &result) const \
e1d3601a
PC
124 { \
125 const Klass *obj = dynamic_cast<const Klass*>(object); \
6c887dde 126 result = wxAny( obj->gettermethod() ); \
e1d3601a
PC
127 } \
128};
129
130#define wxPROPERTY_COLLECTION_ADDER( property, Klass, valueType, addermethod ) \
131class wxPropertyCollectionAdder##property : public wxPropertyCollectionAdder \
132{ \
133public: \
134 wxINFUNC_CLASS_TYPE_FIX(Klass) \
135 wxPropertyCollectionAdder##property() : wxPropertyCollectionAdder( wxT(#addermethod) ) {} \
136 virtual ~wxPropertyCollectionAdder##property() {} \
137 \
6c887dde 138 void Add( wxObject *object, const wxAny &variantValue ) const \
e1d3601a
PC
139 { \
140 Klass *obj = dynamic_cast<Klass*>(object); \
6c887dde
SC
141 valueType tempobj; \
142 if ( variantValue.GetAs(&tempobj) ) \
143 obj->addermethod(tempobj); \
e1d3601a 144 else \
6c887dde 145 obj->addermethod(*wxANY_AS(variantValue, valueType*)); \
e1d3601a
PC
146 } \
147};
148
149#define wxPROPERTY_COLLECTION_GETTER( property, Klass, valueType, gettermethod ) \
150class wxPropertyCollectionGetter##property : public wxPropertyCollectionGetter \
151{ \
152public: \
153 wxINFUNC_CLASS_TYPE_FIX(Klass) \
154 wxPropertyCollectionGetter##property() : wxPropertyCollectionGetter( wxT(#gettermethod) ) {} \
155 virtual ~wxPropertyCollectionGetter##property() {} \
156 \
6c887dde 157 void Get( const wxObject *object, wxAnyList &result) const \
e1d3601a
PC
158 { \
159 const Klass *obj = dynamic_cast<const Klass*>(object); \
160 wxCollectionToVariantArray( obj->gettermethod(), result ); \
161 } \
162};
163
164class WXDLLIMPEXP_BASE wxPropertyAccessor
165{
166public:
167 wxPropertyAccessor( wxPropertySetter *setter, wxPropertyGetter *getter,
168 wxPropertyCollectionAdder *adder, wxPropertyCollectionGetter *collectionGetter )
169 { m_setter = setter; m_getter = getter; m_adder = adder;
170 m_collectionGetter = collectionGetter; }
171
172 virtual ~wxPropertyAccessor() {}
173
174 // Setting a simple property (non-collection)
6c887dde 175 virtual void SetProperty(wxObject *object, const wxAny &value) const
e1d3601a
PC
176 {
177 if ( m_setter )
178 m_setter->Set( object, value );
179 else
180 wxLogError( _("SetProperty called w/o valid setter") );
181 }
182
183 // Getting a simple property (non-collection)
6c887dde 184 virtual void GetProperty(const wxObject *object, wxAny &result) const
e1d3601a
PC
185 {
186 if ( m_getter )
187 m_getter->Get( object, result );
188 else
189 wxLogError( _("GetProperty called w/o valid getter") );
190 }
191
192 // Adding an element to a collection property
6c887dde 193 virtual void AddToPropertyCollection(wxObject *object, const wxAny &value) const
e1d3601a
PC
194 {
195 if ( m_adder )
196 m_adder->Add( object, value );
197 else
198 wxLogError( _("AddToPropertyCollection called w/o valid adder") );
199 }
200
201 // Getting a collection property
6c887dde 202 virtual void GetPropertyCollection( const wxObject *obj, wxAnyList &result) const
e1d3601a
PC
203 {
204 if ( m_collectionGetter )
205 m_collectionGetter->Get( obj, result);
206 else
207 wxLogError( _("GetPropertyCollection called w/o valid collection getter") );
208 }
209
210 virtual bool HasSetter() const { return m_setter != NULL; }
211 virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL; }
212 virtual bool HasGetter() const { return m_getter != NULL; }
213 virtual bool HasAdder() const { return m_adder != NULL; }
214
215 virtual const wxString& GetCollectionGetterName() const
216 { return m_collectionGetter->GetName(); }
217 virtual const wxString& GetGetterName() const
218 { return m_getter->GetName(); }
219 virtual const wxString& GetSetterName() const
220 { return m_setter->GetName(); }
221 virtual const wxString& GetAdderName() const
222 { return m_adder->GetName(); }
223
224protected:
225 wxPropertySetter *m_setter;
226 wxPropertyCollectionAdder *m_adder;
227 wxPropertyGetter *m_getter;
228 wxPropertyCollectionGetter* m_collectionGetter;
229};
230
231class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
232{
233public:
234 wxGenericPropertyAccessor( const wxString &propName );
235 virtual ~wxGenericPropertyAccessor();
236
237 void RenameProperty( const wxString& WXUNUSED_UNLESS_DEBUG(oldName),
238 const wxString& newName )
239 {
240 wxASSERT( oldName == m_propertyName ); m_propertyName = newName;
241 }
242
243 virtual bool HasSetter() const { return true; }
244 virtual bool HasGetter() const { return true; }
245 virtual bool HasAdder() const { return false; }
246 virtual bool HasCollectionGetter() const { return false; }
247
248 virtual const wxString& GetGetterName() const
249 { return m_getterName; }
250 virtual const wxString& GetSetterName() const
251 { return m_setterName; }
252
6c887dde
SC
253 virtual void SetProperty(wxObject *object, const wxAny &value) const;
254 virtual void GetProperty(const wxObject *object, wxAny &value) const;
e1d3601a
PC
255
256 // Adding an element to a collection property
257 virtual void AddToPropertyCollection(wxObject *WXUNUSED(object),
6c887dde 258 const wxAny &WXUNUSED(value)) const
e1d3601a
PC
259 {
260 wxLogError( _("AddToPropertyCollection called on a generic accessor") );
261 }
262
263 // Getting a collection property
264 virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj),
6c887dde 265 wxAnyList &WXUNUSED(result)) const
e1d3601a
PC
266 {
267 wxLogError ( _("GetPropertyCollection called on a generic accessor") );
268 }
269
270private:
271 struct wxGenericPropertyAccessorInternal;
272 wxGenericPropertyAccessorInternal* m_data;
273 wxString m_propertyName;
274 wxString m_setterName;
275 wxString m_getterName;
276};
277
278typedef long wxPropertyInfoFlags;
279enum
280{
281 // will be removed in future releases
282 wxPROP_DEPRECATED = 0x00000001,
283
284 // object graph property, will be streamed with priority (after constructor properties)
285 wxPROP_OBJECT_GRAPH = 0x00000002,
286
287 // this will only be streamed out and in as enum/set, the internal representation
288 // is still a long
289 wxPROP_ENUM_STORE_LONG = 0x00000004,
290
291 // don't stream out this property, needed eg to avoid streaming out children
292 // that are always created by their parents
293 wxPROP_DONT_STREAM = 0x00000008
294};
295
296
297// ----------------------------------------------------------------------------
298// Property Support
299//
300// wxPropertyInfo is used to inquire of the property by name. It doesn't
301// provide access to the property, only information about it. If you
302// want access, look at wxPropertyAccessor.
303// ----------------------------------------------------------------------------
304
305class WXDLLIMPEXP_BASE wxPropertyInfo
306{
9ae4b67f 307 friend class /* WXDLLIMPEXP_BASE */ wxDynamicClassInfo;
e1d3601a
PC
308
309public:
310 wxPropertyInfo(wxPropertyInfo* &iter,
311 wxClassInfo* itsClass,
312 const wxString& name,
313 const wxString& typeName,
314 wxPropertyAccessor *accessor,
6c887dde 315 wxAny dv,
e1d3601a
PC
316 wxPropertyInfoFlags flags = 0,
317 const wxString& helpString = wxEmptyString,
318 const wxString& groupString = wxEmptyString) :
319 m_itsClass(itsClass),
320 m_name(name),
321 m_typeInfo(NULL),
322 m_typeName(typeName),
323 m_collectionElementTypeInfo(NULL),
324 m_accessor(accessor),
325 m_defaultValue(dv),
326 m_flags(flags),
327 m_helpString(helpString),
328 m_groupString(groupString)
329 {
330 Insert(iter);
331 }
332
e1d3601a
PC
333 wxPropertyInfo(wxPropertyInfo* &iter,
334 wxClassInfo* itsClass,
335 const wxString& name,
336 wxEventSourceTypeInfo* type,
337 wxPropertyAccessor *accessor,
6c887dde 338 wxAny dv,
e1d3601a
PC
339 wxPropertyInfoFlags flags = 0,
340 const wxString& helpString = wxEmptyString,
341 const wxString& groupString = wxEmptyString) :
342 m_itsClass(itsClass),
343 m_name(name),
344 m_typeInfo(type),
345 m_collectionElementTypeInfo(NULL),
346 m_accessor(accessor),
347 m_defaultValue(dv),
348 m_flags(flags),
349 m_helpString(helpString),
350 m_groupString(groupString)
351 {
352 Insert(iter);
353 }
354
355 wxPropertyInfo(wxPropertyInfo* &iter,
356 wxClassInfo* itsClass, const wxString& name,
357 const wxString& collectionTypeName,
358 const wxString& elementTypeName,
359 wxPropertyAccessor *accessor,
360 wxPropertyInfoFlags flags = 0,
361 const wxString& helpString = wxEmptyString,
362 const wxString& groupString = wxEmptyString) :
363 m_itsClass(itsClass),
364 m_name(name),
365 m_typeInfo(NULL),
366 m_typeName(collectionTypeName),
367 m_collectionElementTypeInfo(NULL),
368 m_collectionElementTypeName(elementTypeName),
369 m_accessor(accessor),
370 m_flags(flags),
371 m_helpString(helpString),
372 m_groupString(groupString)
373 {
374 Insert(iter);
375 }
376
e1d3601a
PC
377 ~wxPropertyInfo()
378 { Remove(); }
379
380 // return the class this property is declared in
381 const wxClassInfo* GetDeclaringClass() const { return m_itsClass; }
382
383 // return the name of this property
384 const wxString& GetName() const { return m_name; }
385
386 // returns the flags of this property
387 wxPropertyInfoFlags GetFlags() const { return m_flags; }
388
389 // returns the short help string of this property
390 const wxString& GetHelpString() const { return m_helpString; }
391
392 // returns the group string of this property
393 const wxString& GetGroupString() const { return m_groupString; }
394
395 // return the element type info of this property (for collections, otherwise NULL)
396 const wxTypeInfo * GetCollectionElementTypeInfo() const
397 {
398 if ( m_collectionElementTypeInfo == NULL )
399 m_collectionElementTypeInfo = wxTypeInfo::FindType(m_collectionElementTypeName);
400 return m_collectionElementTypeInfo;
401 }
402
403 // return the type info of this property
404 const wxTypeInfo * GetTypeInfo() const
405 {
406 if ( m_typeInfo == NULL )
407 m_typeInfo = wxTypeInfo::FindType(m_typeName);
408 return m_typeInfo;
409 }
410
411 // return the accessor for this property
412 wxPropertyAccessor* GetAccessor() const { return m_accessor; }
413
414 // returns NULL if this is the last property of this class
415 wxPropertyInfo* GetNext() const { return m_next; }
416
417 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
6c887dde 418 wxAny GetDefaultValue() const { return m_defaultValue; }
e1d3601a
PC
419
420private:
421
422 // inserts this property at the end of the linked chain which begins
423 // with "iter" property.
424 void Insert(wxPropertyInfo* &iter);
425
426 // removes this property from the linked chain of the m_itsClass properties.
427 void Remove();
428
429 wxClassInfo* m_itsClass;
430 wxString m_name;
431 mutable wxTypeInfo* m_typeInfo;
432 wxString m_typeName;
433 mutable wxTypeInfo* m_collectionElementTypeInfo;
434 wxString m_collectionElementTypeName;
435 wxPropertyAccessor* m_accessor;
6c887dde 436 wxAny m_defaultValue;
e1d3601a
PC
437 wxPropertyInfoFlags m_flags;
438 wxString m_helpString;
439 wxString m_groupString;
440 wxPropertyInfo* m_next;
441
442 // FIXME: what's this comment about??
443 // string representation of the default value
444 // to be assigned by the designer to the property
445 // when the component is dropped on the container.
446};
447
448WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo*, wxPropertyInfoMap,
449 class WXDLLIMPEXP_BASE );
450
451#define wxBEGIN_PROPERTIES_TABLE(theClass) \
452 wxPropertyInfo *theClass::GetPropertiesStatic() \
453 { \
454 typedef theClass class_t; \
455 static wxPropertyInfo* first = NULL;
456
457#define wxEND_PROPERTIES_TABLE() \
458 return first; }
459
460#define wxHIDE_PROPERTY( pname ) \
461 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
6c887dde 462 wxT(#pname), typeid(void).name(), NULL, wxAny(), wxPROP_DONT_STREAM, \
e1d3601a
PC
463 wxEmptyString, wxEmptyString );
464
465#define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \
466 wxPROPERTY_SETTER( pname, class_t, type, setter ) \
467 static wxPropertySetter##pname _setter##pname; \
468 wxPROPERTY_GETTER( pname, class_t, type, getter ) \
469 static wxPropertyGetter##pname _getter##pname; \
470 static wxPropertyAccessor _accessor##pname( &_setter##pname, \
471 &_getter##pname, NULL, NULL ); \
472 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
473 wxT(#pname), typeid(type).name(), &_accessor##pname, \
6c887dde 474 wxAny(defaultValue), flags, group, help );
e1d3601a
PC
475
476#define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue, \
477 pflags, help, group) \
478 wxPROPERTY_SETTER( pname, class_t, type, setter ) \
479 static wxPropertySetter##pname _setter##pname; \
480 wxPROPERTY_GETTER( pname, class_t, type, getter ) \
481 static wxPropertyGetter##pname _getter##pname; \
482 static wxPropertyAccessor _accessor##pname( &_setter##pname, \
483 &_getter##pname, NULL, NULL ); \
484 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
485 wxT(#pname), typeid(flags).name(), &_accessor##pname, \
6c887dde 486 wxAny(defaultValue), wxPROP_ENUM_STORE_LONG | pflags, help, group );
e1d3601a
PC
487
488#define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \
489 wxPROPERTY_GETTER( pname, class_t, type, getter ) \
490 static wxPropertyGetter##pname _getter##pname; \
491 static wxPropertyAccessor _accessor##pname( NULL, &_getter##pname, NULL, NULL ); \
492 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
493 wxT(#pname), typeid(type).name(),&_accessor##pname, \
6c887dde 494 wxAny(defaultValue), flags, help, group );
e1d3601a
PC
495
496#define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue, \
497 pflags, help, group) \
498 wxPROPERTY_GETTER( pname, class_t, type, getter ) \
499 static wxPropertyGetter##pname _getter##pname; \
500 static wxPropertyAccessor _accessor##pname( NULL, &_getter##pname, NULL, NULL ); \
501 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
502 wxT(#pname), typeid(flags).name(),&_accessor##pname, \
6c887dde 503 wxAny(defaultValue), wxPROP_ENUM_STORE_LONG | pflags, help, group );
e1d3601a
PC
504
505#define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter, \
506 flags, help, group ) \
507 wxPROPERTY_COLLECTION_ADDER( pname, class_t, addelemtype, adder ) \
508 static wxPropertyCollectionAdder##pname _adder##pname; \
509 wxPROPERTY_COLLECTION_GETTER( pname, class_t, colltype, getter ) \
510 static wxPropertyCollectionGetter##pname _collectionGetter##pname; \
511 static wxPropertyAccessor _accessor##pname( NULL, NULL,&_adder##pname, \
512 &_collectionGetter##pname ); \
513 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
514 wxT(#pname), typeid(colltype).name(),typeid(addelemtype).name(), \
515 &_accessor##pname, flags, help, group );
516
517#define wxREADONLY_PROPERTY_COLLECTION( pname, colltype, addelemtype, getter, \
518 flags, help, group) \
519 wxPROPERTY_COLLECTION_GETTER( pname, class_t, colltype, getter ) \
520 static wxPropertyCollectionGetter##pname _collectionGetter##pname; \
521 static wxPropertyAccessor _accessor##pname( NULL, NULL, NULL, \
522 &_collectionGetter##pname ); \
523 static wxPropertyInfo _propertyInfo##pname( first,class_t::GetClassInfoStatic(), \
524 wxT(#pname), typeid(colltype).name(),typeid(addelemtype).name(), \
525 &_accessor##pname, flags, help, group );
526
527#define wxEVENT_PROPERTY( name, eventType, eventClass ) \
528 static wxEventSourceTypeInfo _typeInfo##name( eventType, CLASSINFO( eventClass ) ); \
529 static wxPropertyInfo _propertyInfo##name( first,class_t::GetClassInfoStatic(), \
6c887dde 530 wxT(#name), &_typeInfo##name, NULL, wxAny() );
e1d3601a
PC
531
532#define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) \
533 static wxEventSourceTypeInfo _typeInfo##name( eventType, lastEventType, \
534 CLASSINFO( eventClass ) ); \
535 static wxPropertyInfo _propertyInfo##name( first, class_t::GetClassInfoStatic(), \
6c887dde 536 wxT(#name), &_typeInfo##name, NULL, wxAny() );
e1d3601a
PC
537
538// ----------------------------------------------------------------------------
539// Implementation Helper for Simple Properties
540// ----------------------------------------------------------------------------
541
542#define wxIMPLEMENT_PROPERTY(name, type) \
543private: \
544 type m_##name; \
545public: \
546 void Set##name( type const & p) { m_##name = p; } \
547 type const & Get##name() const { return m_##name; }
548
6c887dde
SC
549WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxAny, wxStringToAnyHashMap,
550 class WXDLLIMPEXP_BASE );
551
e1d3601a
PC
552#endif // wxUSE_EXTENDED_RTTI
553#endif // _XTIPROP_H_