wxArt2D
id.h
Go to the documentation of this file.
1 /*! \file wx/general/id.h
2  \brief Id based property system with its base a2dPropertyId.
3 
4  Properties in wxDocview are template based. Each property type is a unique instance of a
5  specific class, and that is what its ID is. A derived property class with an ID can be
6  used by other classes like a2dObject to store properties in itself. Each property
7  with a specific ID can store the specific information where that property ID class was
8  designed for.
9 
10  \author Michael S�trop
11  \date Created 12/12/2003
12 
13  Copyright: 2003-2004 (c) Michael S�trop
14 
15  Licence: wxWidgets Licence
16 
17  RCS-ID: $Id: id.h,v 1.31 2008/10/30 23:18:09 titato Exp $
18 */
19 
20 #ifndef __ID_H__
21 #define __ID_H__
22 
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26 
27 #include "wx/hashmap.h"
28 #include "wx/filename.h"
29 #include "wx/tipwin.h"
30 #include <wx/uri.h>
31 
32 
33 #include "wx/general/smrtptr.h"
34 
35 //! This macro is used to set as the name of a class
36 /*!
37  a2dPropertyId knows how to create a a2dNamedProperty from itself, and a a2dPropertyId
38  can be found by its name from the hash of all a2dPropertyId's created.
39 */
40 #define CLASSNAME(name) wxT(#name)
41 
42 //! A class for id's of various kinds
43 /*! a2dIdBase is used in situations, where traditionally an enumeration type is used.
44  The disadvantage of an enumeration is, that it cannot easily be expanded by derived
45  classes. If this would be done, all derived classes would share the same id
46  range and would have to know each other. a2dIdBase solves this.
47  Instead of a enum value, a distinct a2dIdBase object is used for identification.
48  The identification is usually done by address. The a2dIdBase objects are generally
49  static members of a class of global variables, so that they are accessable by
50  all objects requiring the id.
51  A a2dIdBase should always be derived of, so that different ID classes cannot be
52  inadvertedly intermixed.
53  A a2dIdBase cannot easily be serialized, because the address will change. To
54  do this, it must be converted to a string form. Derived classes will have ways to
55  do this.
56  Another way to have unique IDs is to use wxNewId. The advantage of a2dIdBase is,
57  that it can be extended to be serialized and that it need not be initialized.
58 
59  \ingroup general
60 */
61 class A2DGENERALDLLEXP a2dIdBase
62 {
63 public:
64  a2dIdBase() {};
65  virtual ~a2dIdBase() {};
66  virtual wxString GetIdClassName() { return wxT( "a2dIdBase" ); }
67 };
68 
69 // some forward declarations required by a2dPropertyId
70 
71 class A2DGENERALDLLEXP a2dObject;
72 class A2DGENERALDLLEXP a2dPropertyId;
73 class A2DGENERALDLLEXP a2dNamedProperty;
74 class A2DGENERALDLLEXP a2dInt16Property;
75 class A2DGENERALDLLEXP a2dInt32Property;
76 class A2DGENERALDLLEXP a2dUint16Property;
77 class A2DGENERALDLLEXP a2dUint32Property;
78 class A2DGENERALDLLEXP a2dBoolProperty;
79 class A2DGENERALDLLEXP a2dFloatProperty;
80 class A2DGENERALDLLEXP a2dDoubleProperty;
81 class A2DGENERALDLLEXP a2dVoidPtrProperty;
82 class A2DGENERALDLLEXP a2dObjectProperty;
83 class A2DGENERALDLLEXP a2dStringProperty;
84 class A2DGENERALDLLEXP a2dFileNameProperty;
85 class A2DGENERALDLLEXP a2dDateTimeProperty;
86 class A2DGENERALDLLEXP a2dMenuProperty;
87 class A2DGENERALDLLEXP a2dUriProperty;
88 class A2DGENERALDLLEXP a2dWindowProperty;
89 class A2DGENERALDLLEXP a2dTipWindowProperty;
90 class A2DGENERALDLLEXP a2dColourProperty;
91 class A2DGENERALDLLEXP a2dArrayStringProperty;
92 class A2DGENERALDLLEXP a2dProperty;
93 class A2DGENERALDLLEXP a2dAutoZeroProperty;
94 class A2DGENERALDLLEXP a2dNamedPropertyList;
95 
96 //! Declaration of the hash map type to convert prop names to prop id objects
97 WX_DECLARE_STRING_HASH_MAP( a2dPropertyId*, a2dPropertyIdHashMap );
98 
99 //! This is the base class for all kinds of property id's for a2dObject
100 /*! Some facts about a2dPropertyId and its derivatives
101 
102  - A a2dPropertyId supplies a unique id, that identifies dynamic properties or
103  members and fields of objects.
104  - A a2dPropertyId knows the value type of a property and can access
105  polymorphic property objects in a typesafe way.
106  - A a2dPropertyId may access structured members/properties e.g.
107  members/properties of members/properties.
108 
109  The a2dPropertyId has a major role in setting a property to an object
110  If a property or member is set to an object, a2dPropertyId does:
111 
112  - Create a local or dynamic property object of proper type from a value.
113  - Sets an individual property/member to an individual object. It can do
114  this either directly (for PTM property ids) or ask the target object
115  to do it (via DoExchangeMembers or DoAddProperty).
116  The last is more flexible, but slower.
117 
118  The first task can obviously only be performed by the property id and not
119  by the target object, because the target object does not have type specific
120  functions.
121 
122  The second task could be performed by the target object directly in many
123  cases, but there are a lot of exceptions, where a propertyId can do it easier:
124 
125  - PTM property ids can do this more efficiently
126  - Property Ids want to control if a property is set as member, list property,
127  if it is set recursively or not.
128 
129  A property or member is set to an object via the following functions
130 
131  - a2dPropertyIdTyped::SetPropertyToObject(obj, value):
132  This function creates from the value a local property object and calls
133  SetProperty( obj, property ).
134 
135  - a2dObject::SetProperty(): This function sets the
136  given property object to an object.
137  The property object given may not be inserted into
138  an object list directly, because it is owned by somebody else or because it is
139  not a dynamic object (i.e. sitting on the stack). So if the function needs
140  to be inserted into a property list, it is cloned before. If the property
141  is set as a member, this is not required.
142 
143  - a2dObject::DoExchangeMembers
144  This function calls the a2dPropertyIdXXX::ExchangeMember function of all properties, for which
145  the object has members. The ExchangeMember function of the property id finally sets or
146  collects, or enumerates one member variable.
147 
148  - a2dObject::DoAddProperty
149  This function finally adds a property object to the property list of a a2dObject.
150 
151  \ingroup general property
152 
153 */
154 class A2DGENERALDLLEXP a2dPropertyId
155 {
156 public:
157  //! Flags for property ids
158  enum Flags
159  {
160  //! no special flags set
161  flag_none = 0x00000000,
162  //! the property is temporary and never saved
163  flag_temporary = 0x00000001,
164  //! transfer this property via a command processor
165  /*! This is most usefull for general properties like styles in a drawing
166  applications.
167  You should set flag_onlymemberhint as well.
168  */
169  flag_transfer = 0x00000002,
170  //! set this property only as member, never as property list item
171  flag_onlymember = 0x00000004,
172  //! this is a hint for DoIgnoreIfNotMember in derived classes
173  /* This is usefull for properties that are sometimes set as non-members,
174  e.g. in the command processor, and sometimes not, e.g. in objects
175  for which the property doesn't make sense.
176  This flag is in now way evaluated by the base property system.
177  It is intended to evaluate this flag in derived classes DoIgnoreIfNotMember.
178  */
179  flag_onlymemberhint = 0x00000008,
180  //! Search the list before searching members
181  /*! This is an optimization flag for properties that are most frequently found
182  in the list (e.g. stroke, fill, ... )
183  */
184  flag_listfirst = 0x00000010,
185  //! Allow adding a specific property with ID more than once to a list
186  /*! If this Id refers to a member, it is still added only once
187  */
188  flag_multiple = 0x00000020,
189  //! When cloning, and this flag is set, the property is cloned deep, else not.
190  /*!
191  In cases like editing, temporary properties are added to a document, which are removed later on.
192  Those properties are not rendered, and only store a pointer to some other a2dObject.
193  In such cases a clone should not be made of the a2dObject pointed to.
194  In cases like fill and stroke properties, it is often required.
195  */
196  flag_clonedeep = 0x00000040,
197  //! Search the list only for this dynamic property
198  /*! This is an optimization flag for properties that are only found
199  in the list
200  */
201  flag_listonly = 0x00000080,
202 
203  //! when set this type of property has no influence on rendering
204  flag_norender = 0x00000100,
205 
206  //! A property id defined by user
207  flag_userDefined = 0x00000200,
208 
209  //! A property id for a property which is editable
210  flag_isEditable = 0x00000400,
211 
212  //! If a property with this id has changed its parent/holder will be notified.
213  flag_notify = 0x00000800
214  };
215  friend Flags operator | ( Flags a, Flags b ) { return ( Flags )( ( int )a | ( int )b ); }
216  friend Flags operator & ( Flags a, Flags b ) { return ( Flags )( ( int )a & ( int )b ); }
217 
218  //! Flags used for manipulating the way a property is set to a2dObject
219  enum SetFlags
220  {
221  //! no special flags set
222  set_none = 0x00000000,
223  //! set the property also to all childs
224  /*! This is NOT evaluated by the property code.
225  This serves a s a hint to a2dObject derived classes
226  */
227  //! set the property only as a member, never as a list item
228  set_onlymember = 0x00000010,
229 
230  //! if the property is found as member, set it, otherwise remove it from the list
231  set_remove_non_member = 0x00000020,
232 
233  //! remove the property, don't set it as member
234  set_remove_property = 0x00000040
235  };
236  friend SetFlags operator | ( SetFlags a, SetFlags b ) { return ( SetFlags )( ( int )a | ( int )b ); }
237 
238 public:
239  //! Default constructor
240  a2dPropertyId( const wxString& name, Flags flags );
241 
242  //! destructor
243  virtual ~a2dPropertyId() {};
244  //! Get the ids print and serialization name
245  virtual wxString GetName() const { return m_name; }
246  //! Set the ids print and serialization name
247  void SetName( const wxString& name ) { m_name = name; }
248  //! Get the main (pre-dot) part of a hierarchical id
249  virtual const a2dPropertyId* GetMainID() const { return this; }
250  //! Get the sub (post-dot) part of a hierarchical id
251  virtual const a2dPropertyId* GetSubID() const { return 0; }
252  //! Check if this id is equal to another id
253  virtual bool operator == ( const a2dPropertyId& other ) const { return &other == this; }
254  //! Create a new property object from a value string
255  virtual a2dNamedProperty* CreatePropertyFromString( const wxString& WXUNUSED( value ) ) const { return 0; };
256 
257  virtual a2dNamedProperty* GetPropertyAsNamedProperty( const a2dObject* obj ) const { return 0; };
258 
259  //! Set the property in obj to value (not cloning value)
260  virtual void SetNamedPropertyToObject( a2dObject* obj, a2dNamedProperty* nprop, SetFlags setflags = set_none ) const;
261 
262  //! Test if this id identifies a property that needs to be cloned deep.
263  bool IsCloneDeep() const { return ( m_flags & flag_clonedeep ) != 0; }
264  //! Test if this id identifies a temporary property
265  bool IsTemporary() const { return ( m_flags & flag_temporary ) != 0; }
266  //! true if this property is transfered via e.g. a command processor
267  bool IsTransfer() const { return ( m_flags & flag_transfer ) != 0; }
268  //! true if this property is only set as member
269  bool IsOnlyMember() const { return ( m_flags & flag_onlymember ) != 0; }
270  //! true if this property has the only set as member hint set
271  bool IsOnlyMemberHint() const { return ( m_flags & flag_onlymemberhint ) != 0; }
272  //! true if this property searches the list first, then members
273  bool IsListFirst() const { return ( m_flags & flag_listfirst ) != 0; }
274  //! true if this property searches the list only
275  bool IsListOnly() const { return ( m_flags & flag_listonly ) != 0; }
276  //! true if this property is user defined
277  bool IsUserDefined() const { return ( m_flags & flag_userDefined ) != 0; }
278  //! true if this property is editable ( can be tested in a property editor ).
279  bool IsEditable() const { return ( m_flags & flag_isEditable ) != 0; }
280 
281  //! check a flag mask (all given flags must be set)
282  bool CheckFlags( Flags flags ) const { return ( m_flags & flags ) == flags; }
283  //! check a property id and flags to see if the property shall be collected
284  bool CheckCollect( const a2dPropertyId* id, Flags flags ) const { return ( !id || id == this ) && ( ( m_flags & flags ) == flags ); }
285 
286  //! Dynamic properties with this id will be removed from the object
287  /*!
288  \param obj the object to remove the properties from
289  \param setflags must at least be set_remove_property ( default ), can be extended to be more specific.
290  */
291  void RemovePropertyFromObject( a2dObject* obj ) const;
292 
293 protected:
294 
295  //! this constructor is only for property ids referencing other property ids
296  a2dPropertyId( );
297 
298  //! this is called by derived classes to add a list property in an object
299  /*! This functions exists because the derived classes are not friend of a2dObject.
300  This function gives access to a2dObject::AddProperty.
301  */
302  inline void DoAddPropertyToObject( a2dObject* obj, a2dNamedProperty* prop ) const;
303 
304  //! this is called by derived to check if a property should be added as non-member
305  /*! This functions exists because the derived classes are not friend of a2dObject.
306  This function gives access to a2dObject::DoIgnoreIfNotMember.
307  */
308  inline bool DoIgnoreIfNotMember( a2dObject* obj ) const;
309 
310  //! this is called by derived classes to change an id in a property
311  /*! This functions exists because the derived classes are not friend of a2dNamedProperty.
312  This function gives access to a2dNamedProperty.
313  */
314  static inline void DoSetPropertyId( a2dNamedProperty* prop, a2dPropertyId* id );
315 
316 protected:
317 
318  wxString m_name;
319 
320  Flags m_flags;
321 
322 private:
323  //!how many references to this object do exist
324  int m_refcount;
325 
326  //! Call to have a new owner for this object
327  /*! This function should only be called by a2dSmrtPtr
328 
329  \remark owning mean that the object calling this member needs to call Release at some time,
330  in order to actually release/delete the object.
331 
332  \return The return value is the object itself, which is now owned on time extra.
333 
334  increment refcount by 1 ( use when adding a reference to this object)
335  */
336  a2dPropertyId* SmrtPtrOwn() { m_refcount++; return this; }
337 
338  //!To release the object, it is not longer owned by the calling object.
339  /*! This function should only be called by a2dSmrtPtr
340  */
341  bool SmrtPtrRelease()
342  {
343  m_refcount--;
344  wxASSERT_MSG( m_refcount >= 0, wxT( "a2dPropertyId Own/Release not matched (extra Release calls)" ) );
345  if ( m_refcount <= 0 )
346  {
347  delete this;
348  return true;
349  }
350  return false;
351  }
352 
353 private:
354  friend class a2dSmrtPtrBase;
355 };
356 
357 #if defined(WXDOCVIEW_USINGDLL)
358 template class A2DGENERALDLLEXP std::allocator<a2dPropertyId* >;
359 template class A2DGENERALDLLEXP std::allocator< std::_List_nod<a2dPropertyId*, std::allocator<a2dPropertyId* > >::_Node >;
360 template class A2DGENERALDLLEXP std::allocator< std::_List_ptr<a2dPropertyId*, std::allocator<a2dPropertyId* > >::_Nodeptr >;
361 template class A2DGENERALDLLEXP std::list<a2dPropertyId* >;
362 template class A2DGENERALDLLEXP a2dlist<a2dPropertyId* >;
363 template class A2DGENERALDLLEXP a2dPtrList<a2dPropertyId>;
364 
365 template class A2DGENERALDLLEXP std::allocator<wxUint16 >;
366 template class A2DGENERALDLLEXP std::allocator< std::_List_nod<wxUint16, std::allocator<wxUint16 > >::_Node >;
367 template class A2DGENERALDLLEXP std::allocator< std::_List_ptr<wxUint16, std::allocator<wxUint16 > >::_Nodeptr >;
368 template class A2DGENERALDLLEXP std::list<wxUint16 >;
369 template class A2DGENERALDLLEXP a2dlist<wxUint16 >;
370 #endif
371 
372 //! list to hold a set of property id objects pointers
374 
375 //! This template class is for property ids meant for properties that do not encapsulate another type.
376 /*! For some properties, the property itself is the value. These properties use a2dPropertyIdProp as id.
377  Other properties encapsulate a value. These properties use wxProperyIdTyped as id.
378 
379  For example, a2dShadowStyleProperty is a property which is normally added as a dynamic property
380  to an a2dCanvasObject. It directly holds the information/value for shadow in its members.
381  So we will use:
382  <code>
383  typedef a2dPropertyIdProp<class a2dShadowStyleProperty> a2dPropertyIdCanvasShadowStyle;
384  </code>
385 
386  If however the property is just holding a single object, it is more handy to use a2dPropertyIdTyped
387  as template, since this has many function to get/set that object without further effort.
388  So for a a2dBoundingBox in a a2dBoudingBoxProperty it is best to use this:
389  <code>
390  typedef a2dPropertyIdTyped<a2dBoundingBox, a2dBoudingBoxProperty> a2dPropertyIdBoundingBox;
391  </code>
392 
393  \ingroup general property
394 
395 */
396 template<class proptype>
398 {
399 public:
400  //! Default constructor
401  a2dPropertyIdProp( const wxString& name, Flags flags ) : a2dPropertyId( name, flags )
402  {
403  }
404 
405  ~a2dPropertyIdProp() {}
406 
407  //! Set the property in obj to value (cloning value)
408  void SetPropertyToObject( a2dObject* obj, const proptype& value ) const;
409  //! Set the property in obj to value (not cloning value)
410  void SetPropertyToObject( a2dObject* obj, proptype* value ) const;
411 
412  //! retrieve in form of a a2dNamedProperty the value of the property identified with this id
413  /*!
414  The property id is defining the way a a2dNamedProperty can be set or retrieved from the a2dObject.
415  In this class only via dynamic properties.
416 
417  \param obj the object on which the property needs to be retrieved
418  */
419  proptype* GetPropertyClone( const a2dObject* obj ) const;
420 
421  //! retrieve in form of a a2dNamedProperty the property identified with this id
422  /*!
423  The property id is defining the way a a2dNamedProperty can be set or retrieved from the a2dObject.
424  The a2dPropertyIdProp is only used for dynamic properties.
425 
426  \param obj the object on which the property needs to be set ot retrieved
427  */
428  a2dNamedProperty* GetPropertyAsNamedProperty( const a2dObject* obj ) const;
429 
430  //! Set the property in obj to value (not cloning value)
431  void SetNamedPropertyToObject( a2dObject* obj, a2dNamedProperty* nprop, SetFlags setflags = set_none ) const;
432 
433  //! Get the property in obj (not cloned)
434  proptype* GetProperty( a2dObject* obj ) const;
435  //! Get the property in obj (const, not cloned)
436  const proptype* GetProperty( const a2dObject* obj ) const;
437 
438 protected:
439  //! this constructor is only for property ids referencing other property ids
441 
442 protected:
443 };
444 
445 //! This template class is for property ids with a known data type
446 /*!
447  When the property type has only a single value stored, this is the template to use,
448  since this has many function to get/set that object without further effort.
449  So for a a2dBoundingBox in a a2dBoudingBoxProperty it is best to use this:
450  <code>
451  typedef a2dPropertyIdTyped<a2dBoundingBox, a2dBoudingBoxProperty> a2dPropertyIdBoundingBox;
452  </code>
453 
454  Assume that a2dCanvasObject has:
455 
456  <code>
457  //declare of static member in the class
458  static const a2dPropertyIdBoundingBox PROPID_BoundingBox;
459 
460  //initialize static member in cpp file
461  const a2dPropertyIdBoundingBox a2dCanvasObject::PROPID_BoundingBox( CLASSNAME( a2dCanvasObject ), wxT("statebox"), a2dPropertyId::flag_temporary|a2dPropertyId::flag_multiple, a2dBoundingBox() );
462 
463  </code>
464  We can set it like this:
465  <code>
466  a2dBoundingBox updatearea(0,0,100,100);
467  a2dCanvasObject::PROPID_BoundingBox->SetPropertyToObject( a_canvasobject, updatearea );
468  a2dBoundingBox updatearea2(0,0,100,100);
469  a2dCanvasObject::PROPID_BoundingBox->SetPropertyToObject( a_canvasobject, updatearea2 );
470  </code>
471 
472  This will give us two dynamic properties (see flag_multiple ) on the a_canvasobject.
473 
474  \ingroup general property
475 */
476 template<class basetype, class proptype>
478 {
479 
480 public:
481 
482  typedef basetype ( wxObject::*Get )() const;
483  typedef const basetype& ( wxObject::*ConstGet )() const;
484  typedef void ( wxObject::*Set )( basetype );
485  typedef void ( wxObject::*ConstSet )( const basetype& value );
486  typedef basetype wxObject::* Mptr;
487 
488  //! constructor for dynamic properties on objects
489  /*!
490  This constructor is for purely dynamic properties ( stored a a2dNamedProperty on a a2dObject ).
491 
492  \param name the name of the propertyId
493  \param flags defines how a property needs to be set and retrieved.
494  \param defaultvalue if property is not available, and still asked for, and allowed as dynamic property, this value is returned.
495  */
496  a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype& defaultvalue );
497 
498  a2dPropertyIdTyped( const wxString& name, basetype defaultvalue, Flags flags = flag_listfirst );
499 
500  //! constructor for Get and Set functions to get the property
501  /*!
502  \param name the name of the propertyId
503  \param flags defines how a property needs to be set and retrieved.
504  \param defaultvalue if property is not available, and still asked for, and allowed as dynamic property, this value is returned.
505  \param getFunc function to get the property to a class member, if NULL property is retrieved in a different manner
506  \param setFunc function to set the property to a class member, if NULL property is set in a different manner
507  */
508  a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype& defaultvalue,
509  Get getFunc, Set setFunc );
510 
511  //! constructor for Get and ConstSet functions to get the property
512  /*!
513  \param name the name of the propertyId
514  \param flags defines how a property needs to be set and retrieved.
515  \param defaultvalue if property is not available, and still asked for, and allowed as dynamic property, this value is returned.
516  \param getFunc function to get the property from a class member, if NULL property is retrieved in a different manner
517  \param setFunc function to set the property to a class member, if NULL property is set in a different manner
518  */
519  a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype& defaultvalue,
520  Get getFunc, ConstSet setFunc );
521 
522  a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype& defaultvalue,
523  ConstGet getFunc, ConstSet setFunc );
524 
525  //! constructor for a pointer to a member variable to get the property
526  /*!
527  \param name the name of the propertyId
528  \param flags defines how a property needs to be set and retrieved.
529  \param defaultvalue if property is not available, and still asked for, and allowed as dynamic property, this value is returned.
530  \param ptm pointer to a class field to get and set the property, if NULL property is retrieved in a different manner
531  */
532  a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype& defaultvalue,
533  Mptr ptm );
534 
535  ~a2dPropertyIdTyped() {}
536 
537  //! Set the property in obj to value
538  void SetPropertyToObject( a2dObject* obj, const basetype& value, SetFlags setflags = set_none ) const;
539 
540  //! Given the object to set the property on, and a a2dNamedProperty to
541  /*!
542  hold the property value and type, set it as a property to the object.
543  */
544  void SetPropertyToObject( a2dObject* obj, proptype* property, SetFlags setflags = set_none ) const;
545 
546  //! retrieve in form of a a2dNamedProperty the value of the property identified with this id
547  /*!
548  The property id is defining the way a a2dNamedProperty can be set or retrieved from the a2dObject.
549  If the m_ptm is set that will be used, else m_get and m_set, and in the end via dynamic properties.
550 
551  \param obj the object on which the property needs to be retrieved
552  */
553  proptype* GetPropertyClone( const a2dObject* obj ) const;
554 
555  a2dNamedProperty* GetPropertyAsNamedProperty( const a2dObject* obj ) const;
556 
557  //! Set the property in obj to value (not cloning value)
558  void SetNamedPropertyToObject( a2dObject* obj, a2dNamedProperty* nprop, SetFlags setflags = set_none ) const;
559 
560  //! Get the property from the list in obj ( no members, not cloned )
561  proptype* GetPropertyListOnly( const a2dObject* obj ) const;
562 
563  //! Get the property value in obj
564  basetype GetPropertyValue( const a2dObject* obj ) const;
565 
566  //! Get the property value in obj, if not found return default value given
567  basetype GetPropertyValue( const a2dObject* obj, const basetype& defaultvalue ) const;
568 
569  //! Get a pointer to the property value in obj
570  basetype* GetPropertyValuePtr( a2dObject* obj ) const;
571 
572  //! Get the default value for this property
573  const basetype& GetDefaultValue() const { return m_defaultvalue; }
574 
575  //! Create a new property object from a value string
576  a2dNamedProperty* CreatePropertyFromString( const wxString& value ) const;
577 
578  //! returns a dummy property id of this type, that can be used in non-id applications
579  /*!
580  Normally properties that are used internal in the library are declared by a a2dPropertyId
581  as a static member of a class.
582  Like this:
583  <code>
584  static const a2dPropertyIdString PROPID_Name;
585  </code>
586  And as this the property id is initialized, as to say what type of property it is and to which class it belongs.
587  <code>
588  const a2dPropertyIdString a2dObject::PROPID_Name( wxT("name"), a2dPropertyId::flag_none, wxT("") );
589  </code>
590 
591  If non of this is required, you can have non id properties.
592  As an example you can have user defined properties, which the program will not know about,
593  and will not treat as setting something inside a class, or holds in a dynamic fashion some information,
594  which the program does use.
595 
596  Like the user can add a dynamic property to a a2dObject, dynamic properties are stored in a2dObject::m_propertylist.
597  And using this function here, you can give such a property the dummy id which is always there as a static existing id.
598  */
599  static a2dPropertyIdTyped<basetype, proptype>* GetDummy();
600 
601 protected:
602  //! this constructor is only for property ids referencing other property ids
604 
605  Get m_get;
606  ConstGet m_constget;
607  Set m_set;
608  ConstSet m_constset;
609 
610  basetype a2dObject::* m_ptm;
611 
612  //! this is the value returned if e.g. a property is not found
613  basetype m_defaultvalue;
614 };
615 
616 class A2DGENERALDLLEXP a2dObject;
617 
618 #if defined(A2DGENERALMAKINGDLL) || defined(WXDOCVIEW_USINGDLL)
619 template class A2DGENERALDLLEXP a2dSmrtPtr<a2dObject>;
620 template class A2DGENERALDLLEXP a2dAutoZeroPtr<a2dObject>;
621 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxInt16, a2dInt16Property> ;
622 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxInt32, a2dInt32Property> ;
623 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxUint16, a2dUint16Property> ;
624 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxUint32, a2dUint32Property> ;
625 template class A2DGENERALDLLEXP a2dPropertyIdTyped<bool, a2dBoolProperty> ;
626 template class A2DGENERALDLLEXP a2dPropertyIdTyped<double, a2dDoubleProperty> ;
627 template class A2DGENERALDLLEXP a2dPropertyIdTyped<float, a2dFloatProperty> ;
628 template class A2DGENERALDLLEXP a2dPropertyIdTyped<void*, a2dVoidPtrProperty> ;
629 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxString, a2dStringProperty> ;
630 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxFileName, a2dFileNameProperty> ;
631 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxDateTime, a2dDateTimeProperty> ;
632 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxMenu*, a2dMenuProperty> ;
633 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxUri, a2dUriProperty> ;
634 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxWindow*, a2dWindowProperty> ;
635 //template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxTipWindow*, a2dTipWindowProperty> ;
636 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxColour, a2dColourProperty> ;
637 template class A2DGENERALDLLEXP a2dPropertyIdTyped<wxArrayString, a2dArrayStringProperty>;
638 template class A2DGENERALDLLEXP a2dPropertyIdTyped<a2dSmrtPtr<a2dObject>, a2dProperty>;
639 template class A2DGENERALDLLEXP a2dPropertyIdTyped<a2dAutoZeroPtr<a2dObject>, a2dAutoZeroProperty>;
640 #endif
641 
642 /*! \addtogroup property
643 * @{
644 */
645 
646 //! property of this type
648 //! property of this type
650 //! property of this type
652 //! property of this type
654 //! property of this type
656 //! property of this type
658 //! property of this type
660 //! property of this type
662 //! property of this type
664 //! property of this type
666 //! property of this type
668 //! property of this type
670 //! property of this type
672 //! property of this type
674 //! property of this type
676 //typedef a2dPropertyIdTyped<wxTipWindow*, a2dWindowProperty> a2dPropertyIdTipWindow;
678 //! property of this type
680 //! property of this type
681 typedef a2dPropertyIdTyped<a2dSmrtPtr<a2dObject>, a2dProperty> a2dPropertyIdRefObject;
682 //! property of this type
683 typedef a2dPropertyIdTyped<a2dAutoZeroPtr<a2dObject>, a2dAutoZeroProperty> a2dPropertyIdRefObjectAutoZero;
684 
685 //! @} property
686 
687 /*============================*/
688 
689 //! to define a get set property more easily
690 #define A2D_PROPID_GSI_F( type, classname , propname, defaultval, flags ) \
691  PROPID_##propname = new type( wxT(#propname), \
692  flags, defaultval, \
693  static_cast < type::Get >( &classname::Get##propname), \
694  static_cast < type::Set >( &classname::Set##propname) ); \
695  AddPropertyId( PROPID_##propname );
696 
697 //! to define a get set property more easily
698 #define A2D_PROPID_GSI( type, classname , propname, defaultval ) \
699  A2D_PROPID_GSI_F( type, classname, propname, defaultval, a2dPropertyId::flag_none )
700 
701 //! to define a get set property more easily
702 #define A2D_PROPID_GS_F( type, classname, propname, defaultval, fget, fset, flags ) \
703  PROPID_##propname = new type( wxT(#propname), \
704  flags, defaultval, \
705  static_cast < type::Get >( &classname::fget), \
706  static_cast < type::Set >( &classname::fset) ) ; \
707  AddPropertyId( PROPID_##propname );
708 
709 //! to define a get set property more easily
710 #define A2D_PROPID_GS( type, classname , propname, defaultval, fget, fset ) \
711  A2D_PROPID_GS_F( type, classname, propname, defaultval, fget, fset, a2dPropertyId::flag_none )
712 
713 //! to define a get set property more easily
714 #define A2D_PROPID_D_F( type, propname, defaultval, flags ) \
715  PROPID_##propname = new type( wxT(#propname), \
716  flags, defaultval ); \
717  AddPropertyId( PROPID_##propname );
718 
719 #define A2D_PROPID_D( type, propname, defaultval ) \
720  A2D_PROPID_D_F( type, propname, defaultval, a2dPropertyId::flag_none )
721 
722 //! to define a get set property more easily
723 #define A2D_PROPID_M_F( type, classname , propname, defaultval, mptr, flags ) \
724  PROPID_##propname = new type( wxT(#propname), \
725  flags, defaultval, \
726  static_cast < type::Mptr >( &classname::mptr) ); \
727  AddPropertyId( PROPID_##propname );
728 
729 //! to define a get set property more easily
730 #define A2D_PROPID_M( type, classname, propname, defaultval, mptr ) \
731  A2D_PROPID_M_F( type, classname, propname, defaultval, mptr, a2dPropertyId::flag_none )
732 
733 
734 
735 //! Like a2dPropertyIdTyped, but always references a certain member Get and Set function in a certain class
736 //! \ingroup property
737 template<class basetype, class proptype >
738 class a2dPropertyIdGetSet : public a2dPropertyIdTyped< basetype, proptype >
739 {
740 public:
741 
742  //! get method
743  typedef basetype ( a2dObject::*Get )() const;
744  //! set method
745  typedef void ( a2dObject::*Set )( basetype );
746  //! constant get method
747  typedef void ( a2dObject::*ConstSet )( const basetype& value );
748  //! member pointer
749  typedef basetype a2dObject::* Mptr;
750 
751  //! constructor
752  a2dPropertyIdGetSet( const wxString& name, a2dPropertyId::Flags flags, const basetype& defaultvalue,
753  Get getFunc, Set setFunc
754  );
755 
756  //! constructor
757  a2dPropertyIdGetSet( const wxString& name, a2dPropertyId::Flags flags, const basetype& defaultvalue,
758  Get getFunc, ConstSet setFunc
759  );
760 
761  //! Set the property value in obj
762  bool SetPropertyToObject( a2dObject* obj, const basetype& value ) const;
763 
764  //! Get the property value in obj
765  basetype GetPropertyValue( const a2dObject* obj ) const;
766 
767  //! Get the property value in obj, if not found return default value given
768  basetype GetPropertyValue( const a2dObject* obj, const basetype& defaultvalue ) const;
769 
770  //! Get the property in obj (cloned)
771  proptype* GetPropertyClone( const a2dObject* obj ) const;
772 
773  a2dNamedProperty* GetPropertyAsNamedProperty( const a2dObject* obj ) const;
774 
775 };
776 
777 //! get set property id for boolean property
778 //! \ingroup property
780 
781 //! Like a2dPropertyIdTyped, but always references a certain member in a certain class
782 /*!
783  \ingroup property
784 */
785 template<class basetype, class proptype>
786 class a2dMemberDclrTyped : public a2dPropertyIdTyped<basetype, proptype>
787 {
788 public:
789 
790  a2dMemberDclrTyped ( basetype a2dObject::* ptm ) : a2dPropertyIdTyped<basetype, proptype>( ) { m_ptm = ptm; }
791  bool SetPropertyToObject( a2dObject* obj, const basetype& value ) const;
792  proptype* GetPropertyClone( const a2dObject* obj ) const;
793 
794  //! Get the property value in obj
795  basetype GetPropertyValue( const a2dObject* obj ) const;
796 
797  //! Get the property value in obj, if not found return default value given
798  basetype GetPropertyValue( const a2dObject* obj, const basetype& defaultvalue ) const;
799 
800 protected:
801 
802  //! pointer to member
803  basetype a2dObject::* m_ptm;
804 };
805 
806 #if defined(WXDOCVIEW_USINGDLL)
807 template class A2DGENERALDLLEXP a2dMemberDclrTyped<wxInt16, a2dInt16Property> ;
808 template class A2DGENERALDLLEXP a2dMemberDclrTyped<wxInt32, a2dInt32Property> ;
809 template class A2DGENERALDLLEXP a2dMemberDclrTyped<wxUint16, a2dUint16Property> ;
810 template class A2DGENERALDLLEXP a2dMemberDclrTyped<wxUint32, a2dUint32Property> ;
811 template class A2DGENERALDLLEXP a2dMemberDclrTyped<bool, a2dBoolProperty> ;
812 template class A2DGENERALDLLEXP a2dMemberDclrTyped<double, a2dDoubleProperty> ;
813 template class A2DGENERALDLLEXP a2dMemberDclrTyped<void*, a2dVoidPtrProperty> ;
814 template class A2DGENERALDLLEXP a2dMemberDclrTyped<wxString, a2dStringProperty> ;
815 template class A2DGENERALDLLEXP a2dMemberDclrTyped<wxFileName, a2dFileNameProperty> ;
816 template class A2DGENERALDLLEXP a2dMemberDclrTyped<wxColour, a2dColourProperty> ;
817 template class A2DGENERALDLLEXP a2dMemberDclrTyped<wxArrayString, a2dArrayStringProperty> ;
818 #endif
819 
820 /*! \addtogroup property
821 * @{
822 */
823 
824 //! for member associated properties of this type
826 //! for member associated properties of this type
828 //! for member associated properties of this type
830 //! for member associated properties of this type
832 //! for member associated properties of this type
834 //! for member associated properties of this type
836 //! for member associated properties of this type
838 //! for member associated properties of this type
840 //! for member associated properties of this type
842 //! for member associated properties of this type
844 //! for member associated properties of this type
845 typedef a2dMemberDclrTyped<wxArrayString, a2dArrayStringProperty> wxMemberDclrArrayString;
846 
847 //! @} property
848 
849 #endif
850 
a2dPropertyIdTyped< wxMenu *, a2dMenuProperty > a2dPropertyIdMenu
property of this type
Definition: id.h:671
property to hold an unsigned 4 byte integer type variable to be associated with a a2dObject ...
Definition: gen.h:2453
(In) Visible property that can be added to Docview Objects.
Definition: gen.h:1785
basetype(a2dObject::* Get)() const
get method
Definition: id.h:743
bool SetPropertyToObject(a2dObject *obj, const basetype &value) const
Set the property value in obj.
Definition: id.inl:439
property to hold a a2dObject pointer type variable to be associated with a a2dObject ...
Definition: gen.h:2250
a2dPropertyIdProp(const wxString &name, Flags flags)
Default constructor.
Definition: id.h:401
basetype GetPropertyValue(const a2dObject *obj) const
Get the property value in obj.
Definition: id.inl:499
a2dPropertyIdTyped< wxUint32, a2dUint32Property > a2dPropertyIdUint32
property of this type
Definition: id.h:653
a2dDocumentRenderStyle operator|(a2dDocumentRenderStyle a, a2dDocumentRenderStyle b)
OR-ing a2dDocumentRenderStyle is allowed.
Definition: canglob.h:50
virtual wxString GetName() const
Get the ids print and serialization name.
Definition: id.h:245
a2dPropertyIdGetSet(const wxString &name, a2dPropertyId::Flags flags, const basetype &defaultvalue, Get getFunc, Set setFunc)
constructor
Definition: id.inl:427
a2dPropertyIdTyped< wxString, a2dStringProperty > a2dPropertyIdString
property of this type
Definition: id.h:665
a2dMemberDclrTyped< wxFileName, a2dFileNameProperty > wxMemberDclrFileName
for member associated properties of this type
Definition: id.h:841
Ref Counted base object.
Definition: gen.h:1045
Flags
Flags for property ids.
Definition: id.h:158
a2dMemberDclrTyped< wxInt32, a2dInt32Property > wxMemberDclrInt32
for member associated properties of this type
Definition: id.h:827
a2dPropertyIdTyped< wxURI, a2dUriProperty > a2dPropertyIdUri
property of this type
Definition: id.h:673
This template class is for property ids meant for properties that do not encapsulate another type...
Definition: id.h:397
a2dPropertyIdTyped< wxFileName, a2dFileNameProperty > a2dPropertyIdFileName
property of this type
Definition: id.h:667
void(a2dObject::* Set)(basetype)
set method
Definition: id.h:745
property to hold a double type variable to be associated with a a2dObject
Definition: gen.h:2503
a2dPropertyIdTyped< wxInt32, a2dInt32Property > a2dPropertyIdInt32
property of this type
Definition: id.h:649
property to hold a bool type variable to be associated with a a2dObject
Definition: gen.h:2004
void SetName(const wxString &name)
Set the ids print and serialization name.
Definition: id.h:247
bool IsCloneDeep() const
Test if this id identifies a property that needs to be cloned deep.
Definition: id.h:263
bool IsOnlyMember() const
true if this property is only set as member
Definition: id.h:269
proptype * GetPropertyClone(const a2dObject *obj) const
Get the property in obj (cloned)
Definition: id.inl:469
a2dPropertyIdGetSet< bool, a2dBoolProperty > a2dPropertyIdBoolGetSet
Definition: id.h:779
bool IsOnlyMemberHint() const
true if this property has the only set as member hint set
Definition: id.h:271
a2dPropertyIdTyped< bool, a2dBoolProperty > a2dPropertyIdBool
property of this type
Definition: id.h:655
property to hold a wxURI type variable to be associated with a a2dObject
Definition: gen.h:3095
A trivial base class for a2dSmrtPtr. Non-template class, so that it can.
Definition: smrtptr.h:55
list of a2dNamedProperty objects
Definition: gen.h:804
bool IsTemporary() const
Test if this id identifies a temporary property.
Definition: id.h:265
a2dPropertyIdTyped< float, a2dFloatProperty > a2dPropertyIdFloat
property of this type
Definition: id.h:659
a2dPropertyIdTyped< wxArrayString, a2dArrayStringProperty > a2dPropertyIdArrayString
property of this type
Definition: id.h:679
a2dPropertyIdProp()
this constructor is only for property ids referencing other property ids
Definition: id.h:440
property to hold a window type variable (for example wxTipWindow) to be associated with a a2dObject ...
Definition: gen.h:2806
a2dPropertyIdTyped< a2dSmrtPtr< a2dObject >, a2dProperty > a2dPropertyIdRefObject
property of this type
Definition: id.h:681
property to hold a FileName type variable to be associated with a a2dObject
Definition: gen.h:3035
property to hold a a2dObjectPtr smart pointer type variable to be associated with a a2dObject ...
Definition: gen.h:2199
property to hold a wxArrayString type variable to be associated with a a2dObject
Definition: gen.h:2605
virtual ~a2dPropertyId()
destructor
Definition: id.h:243
property to hold a 2 byte integer type variable to be associated with a a2dObject ...
Definition: gen.h:2301
bool IsListFirst() const
true if this property searches the list first, then members
Definition: id.h:273
a2dMemberDclrTyped< wxArrayString, a2dArrayStringProperty > wxMemberDclrArrayString
for member associated properties of this type
Definition: id.h:845
property to hold a wxDateTime type variable to be associated with a a2dObject
Definition: gen.h:2710
SetFlags
Flags used for manipulating the way a property is set to a2dObject.
Definition: id.h:219
const basetype & GetDefaultValue() const
Get the default value for this property.
Definition: id.h:573
basetype GetPropertyValue(const a2dObject *obj) const
Get the property value in obj.
Definition: id.inl:449
property to hold a 2 byte integer type variable to be associated with a a2dObject ...
Definition: gen.h:2401
std list compatible list
Definition: a2dlist.h:42
a2dPropertyIdTyped< wxDateTime, a2dDateTimeProperty > a2dPropertyIdDateTime
property of this type
Definition: id.h:669
bool CheckFlags(Flags flags) const
check a flag mask (all given flags must be set)
Definition: id.h:282
a2dPropertyIdTyped< wxObject, a2dObjectProperty > a2dPropertyIdObject
property of this type
Definition: id.h:663
bool IsUserDefined() const
true if this property is user defined
Definition: id.h:277
property to hold a Menu type variable to be associated with a a2dObject
Definition: gen.h:2764
a2dPropertyIdTyped< wxUint16, a2dUint16Property > a2dPropertyIdUint16
property of this type
Definition: id.h:651
bool IsListOnly() const
true if this property searches the list only
Definition: id.h:275
void(a2dObject::* ConstSet)(const basetype &value)
constant get method
Definition: id.h:747
virtual const a2dPropertyId * GetSubID() const
Get the sub (post-dot) part of a hierarchical id.
Definition: id.h:251
A class for id&#39;s of various kinds.
Definition: id.h:61
WX_DECLARE_STRING_HASH_MAP(a2dPropertyId *, a2dPropertyIdHashMap)
Declaration of the hash map type to convert prop names to prop id objects.
basetype a2dObject::* Mptr
member pointer
Definition: id.h:749
a2dMemberDclrTyped< wxUint32, a2dUint32Property > wxMemberDclrUint32
for member associated properties of this type
Definition: id.h:831
property to hold a tip window type variable to be associated with a a2dObject
Definition: gen.h:2850
property to hold a wxString type variable to be associated with a a2dObject
Definition: gen.h:2066
basetype a2dObject::* m_ptm
pointer to member
Definition: id.h:803
virtual const a2dPropertyId * GetMainID() const
Get the main (pre-dot) part of a hierarchical id.
Definition: id.h:249
a2dPropertyIdTyped< a2dAutoZeroPtr< a2dObject >, a2dAutoZeroProperty > a2dPropertyIdRefObjectAutoZero
property of this type
Definition: id.h:683
a2dPropertyIdTyped()
this constructor is only for property ids referencing other property ids
Definition: id.h:603
property to hold a void pointer type variable to be associated with a a2dObject
Definition: gen.h:2117
bool IsTransfer() const
true if this property is transfered via e.g. a command processor
Definition: id.h:267
This is the base class for all kinds of property id&#39;s for a2dObject.
Definition: id.h:154
a2dMemberDclrTyped< wxUint16, a2dUint16Property > wxMemberDclrUint16
for member associated properties of this type
Definition: id.h:829
a2dMemberDclrTyped< void *, a2dVoidPtrProperty > wxMemberDclrVoidPtr
for member associated properties of this type
Definition: id.h:837
property to hold a wxObject variable to be associated with a a2dObject
Definition: gen.h:2164
smart pointer class and list.
basetype m_defaultvalue
this is the value returned if e.g. a property is not found
Definition: id.h:613
a2dMemberDclrTyped< wxInt16, a2dInt16Property > wxMemberDclrInt16
for member associated properties of this type
Definition: id.h:825
a2dMemberDclrTyped< bool, a2dBoolProperty > wxMemberDclrBool
for member associated properties of this type
Definition: id.h:833
a2dMemberDclrTyped< wxString, a2dStringProperty > wxMemberDclrString
for member associated properties of this type
Definition: id.h:839
a2dPropertyIdTyped< wxInt16, a2dInt16Property > a2dPropertyIdInt16
property of this type
Definition: id.h:647
bool IsEditable() const
true if this property is editable ( can be tested in a property editor ).
Definition: id.h:279
a2dMemberDclrTyped< wxColour, a2dColourProperty > wxMemberDclrColour
for member associated properties of this type
Definition: id.h:843
This template class is for property ids with a known data type.
Definition: id.h:477
bool CheckCollect(const a2dPropertyId *id, Flags flags) const
check a property id and flags to see if the property shall be collected
Definition: id.h:284
Like a2dPropertyIdTyped, but always references a certain member in a certain class.
Definition: id.h:786
property to hold a FileName type variable to be associated with a a2dObject
Definition: gen.h:2656
a2dPropertyIdTyped< wxWindow *, a2dWindowProperty > a2dPropertyIdWindow
property of this type
Definition: id.h:675
a2dMemberDclrTyped< double, a2dDoubleProperty > wxMemberDclrDouble
for member associated properties of this type
Definition: id.h:835
property to hold a float type variable to be associated with a a2dObject
Definition: gen.h:2553
virtual a2dNamedProperty * CreatePropertyFromString(const wxString &value) const
Create a new property object from a value string.
Definition: id.h:255
property to hold an unsigned 2 byte integer type variable to be associated with a a2dObject ...
Definition: gen.h:2351
a2dPropertyIdTyped< double, a2dDoubleProperty > a2dPropertyIdDouble
property of this type
Definition: id.h:657
a2dPropertyIdTyped< void *, a2dVoidPtrProperty > a2dPropertyIdVoidPtr
property of this type
Definition: id.h:661
a2dSmrtPtrList< a2dPropertyId > a2dPropertyIdList
list to hold a set of property id objects pointers
Definition: id.h:373
id.h Source File -- Sun Oct 12 2014 17:04:21 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation