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