]> git.saurik.com Git - wxWidgets.git/blob - include/wx/xtiprop.h
Minor changes, just trim trailing spaces in webview code.
[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 /*
24 class WXDLLIMPEXP_BASE wxObject;
25 class WXDLLIMPEXP_BASE wxClassInfo;
26 class WXDLLIMPEXP_BASE wxDynamicClassInfo;
27 */
28 class WXDLLIMPEXP_BASE wxHashTable;
29 class WXDLLIMPEXP_BASE wxHashTable_Node;
30 class WXDLLIMPEXP_BASE wxEvent;
31 class 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
41 class WXDLLIMPEXP_BASE wxPropertySetter
42 {
43 public:
44 wxPropertySetter( const wxString name ) { m_name = name; }
45 virtual ~wxPropertySetter() {}
46
47 virtual void Set( wxObject *object, const wxAny &variantValue ) const = 0;
48 const wxString& GetName() const { return m_name; }
49
50 private:
51 wxString m_name;
52 };
53
54 class WXDLLIMPEXP_BASE wxPropertyGetter
55 {
56 public:
57 wxPropertyGetter( const wxString name ) { m_name = name; }
58 virtual ~wxPropertyGetter() {}
59
60 virtual void Get( const wxObject *object, wxAny& result) const = 0;
61 const wxString& GetName() const { return m_name; }
62
63 private:
64 wxString m_name;
65 };
66
67 class WXDLLIMPEXP_BASE wxPropertyCollectionGetter
68 {
69 public:
70 wxPropertyCollectionGetter( const wxString name ) { m_name = name; }
71 virtual ~wxPropertyCollectionGetter() {}
72
73 virtual void Get( const wxObject *object, wxAnyList& result) const = 0;
74 const wxString& GetName() const { return m_name; }
75
76 private:
77 wxString m_name;
78 };
79
80 template<typename coll_t> void WXDLLIMPEXP_BASE \
81 wxCollectionToVariantArray( const coll_t& coll, wxAnyList& result );
82
83 class WXDLLIMPEXP_BASE wxPropertyCollectionAdder
84 {
85 public:
86 wxPropertyCollectionAdder( const wxString name ) { m_name = name; }
87 virtual ~wxPropertyCollectionAdder() {}
88
89 virtual void Add( wxObject *object, const wxAny &variantValue ) const= 0;
90 const wxString& GetName() const { return m_name; }
91
92 private:
93 wxString m_name;
94 };
95
96 #define wxPROPERTY_SETTER( property, Klass, valueType, setterMethod ) \
97 class wxPropertySetter##property : public wxPropertySetter \
98 { \
99 public: \
100 wxINFUNC_CLASS_TYPE_FIX(Klass) \
101 wxPropertySetter##property() : wxPropertySetter( wxT(#setterMethod) ) {} \
102 virtual ~wxPropertySetter##property() {} \
103 \
104 void Set( wxObject *object, const wxAny &variantValue ) const \
105 { \
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 } \
113 };
114
115 #define wxPROPERTY_GETTER( property, Klass, valueType, gettermethod ) \
116 class wxPropertyGetter##property : public wxPropertyGetter \
117 { \
118 public: \
119 wxINFUNC_CLASS_TYPE_FIX(Klass) \
120 wxPropertyGetter##property() : wxPropertyGetter( wxT(#gettermethod) ) {} \
121 virtual ~wxPropertyGetter##property() {} \
122 \
123 void Get( const wxObject *object, wxAny &result) const \
124 { \
125 const Klass *obj = dynamic_cast<const Klass*>(object); \
126 result = wxAny( obj->gettermethod() ); \
127 } \
128 };
129
130 #define wxPROPERTY_COLLECTION_ADDER( property, Klass, valueType, addermethod ) \
131 class wxPropertyCollectionAdder##property : public wxPropertyCollectionAdder \
132 { \
133 public: \
134 wxINFUNC_CLASS_TYPE_FIX(Klass) \
135 wxPropertyCollectionAdder##property() : wxPropertyCollectionAdder( wxT(#addermethod) ) {} \
136 virtual ~wxPropertyCollectionAdder##property() {} \
137 \
138 void Add( wxObject *object, const wxAny &variantValue ) const \
139 { \
140 Klass *obj = dynamic_cast<Klass*>(object); \
141 valueType tempobj; \
142 if ( variantValue.GetAs(&tempobj) ) \
143 obj->addermethod(tempobj); \
144 else \
145 obj->addermethod(*wxANY_AS(variantValue, valueType*)); \
146 } \
147 };
148
149 #define wxPROPERTY_COLLECTION_GETTER( property, Klass, valueType, gettermethod ) \
150 class wxPropertyCollectionGetter##property : public wxPropertyCollectionGetter \
151 { \
152 public: \
153 wxINFUNC_CLASS_TYPE_FIX(Klass) \
154 wxPropertyCollectionGetter##property() : wxPropertyCollectionGetter( wxT(#gettermethod) ) {} \
155 virtual ~wxPropertyCollectionGetter##property() {} \
156 \
157 void Get( const wxObject *object, wxAnyList &result) const \
158 { \
159 const Klass *obj = dynamic_cast<const Klass*>(object); \
160 wxCollectionToVariantArray( obj->gettermethod(), result ); \
161 } \
162 };
163
164 class WXDLLIMPEXP_BASE wxPropertyAccessor
165 {
166 public:
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)
175 virtual void SetProperty(wxObject *object, const wxAny &value) const
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)
184 virtual void GetProperty(const wxObject *object, wxAny &result) const
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
193 virtual void AddToPropertyCollection(wxObject *object, const wxAny &value) const
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
202 virtual void GetPropertyCollection( const wxObject *obj, wxAnyList &result) const
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
224 protected:
225 wxPropertySetter *m_setter;
226 wxPropertyCollectionAdder *m_adder;
227 wxPropertyGetter *m_getter;
228 wxPropertyCollectionGetter* m_collectionGetter;
229 };
230
231 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
232 {
233 public:
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
253 virtual void SetProperty(wxObject *object, const wxAny &value) const;
254 virtual void GetProperty(const wxObject *object, wxAny &value) const;
255
256 // Adding an element to a collection property
257 virtual void AddToPropertyCollection(wxObject *WXUNUSED(object),
258 const wxAny &WXUNUSED(value)) const
259 {
260 wxLogError( _("AddToPropertyCollection called on a generic accessor") );
261 }
262
263 // Getting a collection property
264 virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj),
265 wxAnyList &WXUNUSED(result)) const
266 {
267 wxLogError ( _("GetPropertyCollection called on a generic accessor") );
268 }
269
270 private:
271 struct wxGenericPropertyAccessorInternal;
272 wxGenericPropertyAccessorInternal* m_data;
273 wxString m_propertyName;
274 wxString m_setterName;
275 wxString m_getterName;
276 };
277
278 typedef long wxPropertyInfoFlags;
279 enum
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
305 class WXDLLIMPEXP_BASE wxPropertyInfo
306 {
307 friend class /* WXDLLIMPEXP_BASE */ wxDynamicClassInfo;
308
309 public:
310 wxPropertyInfo(wxPropertyInfo* &iter,
311 wxClassInfo* itsClass,
312 const wxString& name,
313 const wxString& typeName,
314 wxPropertyAccessor *accessor,
315 wxAny dv,
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
333 wxPropertyInfo(wxPropertyInfo* &iter,
334 wxClassInfo* itsClass,
335 const wxString& name,
336 wxEventSourceTypeInfo* type,
337 wxPropertyAccessor *accessor,
338 wxAny dv,
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
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
418 wxAny GetDefaultValue() const { return m_defaultValue; }
419
420 private:
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;
436 wxAny m_defaultValue;
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
448 // stl is giving problems when forwarding declarations, therefore we define it as a subclass
449
450 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo*, wxPropertyInfoMapBase,
451 class WXDLLIMPEXP_BASE );
452
453 class WXDLLIMPEXP_BASE wxPropertyInfoMap : public wxPropertyInfoMapBase {
454 };
455
456 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxAny, wxStringToAnyHashMapBase,
457 class WXDLLIMPEXP_BASE );
458
459 class WXDLLIMPEXP_FWD_BASE wxStringToAnyHashMap : public wxStringToAnyHashMapBase {
460 };
461
462 #define wxBEGIN_PROPERTIES_TABLE(theClass) \
463 wxPropertyInfo *theClass::GetPropertiesStatic() \
464 { \
465 typedef theClass class_t; \
466 static wxPropertyInfo* first = NULL;
467
468 #define wxEND_PROPERTIES_TABLE() \
469 return first; }
470
471 #define wxHIDE_PROPERTY( pname ) \
472 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
473 wxT(#pname), typeid(void).name(), NULL, wxAny(), wxPROP_DONT_STREAM, \
474 wxEmptyString, wxEmptyString );
475
476 #define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \
477 wxPROPERTY_SETTER( pname, class_t, type, setter ) \
478 static wxPropertySetter##pname _setter##pname; \
479 wxPROPERTY_GETTER( pname, class_t, type, getter ) \
480 static wxPropertyGetter##pname _getter##pname; \
481 static wxPropertyAccessor _accessor##pname( &_setter##pname, \
482 &_getter##pname, NULL, NULL ); \
483 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
484 wxT(#pname), typeid(type).name(), &_accessor##pname, \
485 wxAny(defaultValue), flags, group, help );
486
487 #define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue, \
488 pflags, help, group) \
489 wxPROPERTY_SETTER( pname, class_t, type, setter ) \
490 static wxPropertySetter##pname _setter##pname; \
491 wxPROPERTY_GETTER( pname, class_t, type, getter ) \
492 static wxPropertyGetter##pname _getter##pname; \
493 static wxPropertyAccessor _accessor##pname( &_setter##pname, \
494 &_getter##pname, NULL, NULL ); \
495 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
496 wxT(#pname), typeid(flags).name(), &_accessor##pname, \
497 wxAny(defaultValue), wxPROP_ENUM_STORE_LONG | pflags, help, group );
498
499 #define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \
500 wxPROPERTY_GETTER( pname, class_t, type, getter ) \
501 static wxPropertyGetter##pname _getter##pname; \
502 static wxPropertyAccessor _accessor##pname( NULL, &_getter##pname, NULL, NULL ); \
503 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
504 wxT(#pname), typeid(type).name(),&_accessor##pname, \
505 wxAny(defaultValue), flags, help, group );
506
507 #define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue, \
508 pflags, help, group) \
509 wxPROPERTY_GETTER( pname, class_t, type, getter ) \
510 static wxPropertyGetter##pname _getter##pname; \
511 static wxPropertyAccessor _accessor##pname( NULL, &_getter##pname, NULL, NULL ); \
512 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
513 wxT(#pname), typeid(flags).name(),&_accessor##pname, \
514 wxAny(defaultValue), wxPROP_ENUM_STORE_LONG | pflags, help, group );
515
516 #define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter, \
517 flags, help, group ) \
518 wxPROPERTY_COLLECTION_ADDER( pname, class_t, addelemtype, adder ) \
519 static wxPropertyCollectionAdder##pname _adder##pname; \
520 wxPROPERTY_COLLECTION_GETTER( pname, class_t, colltype, getter ) \
521 static wxPropertyCollectionGetter##pname _collectionGetter##pname; \
522 static wxPropertyAccessor _accessor##pname( NULL, NULL,&_adder##pname, \
523 &_collectionGetter##pname ); \
524 static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
525 wxT(#pname), typeid(colltype).name(),typeid(addelemtype).name(), \
526 &_accessor##pname, flags, help, group );
527
528 #define wxREADONLY_PROPERTY_COLLECTION( pname, colltype, addelemtype, getter, \
529 flags, help, group) \
530 wxPROPERTY_COLLECTION_GETTER( pname, class_t, colltype, getter ) \
531 static wxPropertyCollectionGetter##pname _collectionGetter##pname; \
532 static wxPropertyAccessor _accessor##pname( NULL, NULL, NULL, \
533 &_collectionGetter##pname ); \
534 static wxPropertyInfo _propertyInfo##pname( first,class_t::GetClassInfoStatic(), \
535 wxT(#pname), typeid(colltype).name(),typeid(addelemtype).name(), \
536 &_accessor##pname, flags, help, group );
537
538 #define wxEVENT_PROPERTY( name, eventType, eventClass ) \
539 static wxEventSourceTypeInfo _typeInfo##name( eventType, CLASSINFO( eventClass ) ); \
540 static wxPropertyInfo _propertyInfo##name( first,class_t::GetClassInfoStatic(), \
541 wxT(#name), &_typeInfo##name, NULL, wxAny() );
542
543 #define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) \
544 static wxEventSourceTypeInfo _typeInfo##name( eventType, lastEventType, \
545 CLASSINFO( eventClass ) ); \
546 static wxPropertyInfo _propertyInfo##name( first, class_t::GetClassInfoStatic(), \
547 wxT(#name), &_typeInfo##name, NULL, wxAny() );
548
549 // ----------------------------------------------------------------------------
550 // Implementation Helper for Simple Properties
551 // ----------------------------------------------------------------------------
552
553 #define wxIMPLEMENT_PROPERTY(name, type) \
554 private: \
555 type m_##name; \
556 public: \
557 void Set##name( type const & p) { m_##name = p; } \
558 type const & Get##name() const { return m_##name; }
559
560 #endif // wxUSE_EXTENDED_RTTI
561 #endif // _XTIPROP_H_