adding new files for xti merge

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66544 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2011-01-03 17:43:49 +00:00
parent e4c3d9409a
commit cc3977bf13
28 changed files with 5654 additions and 0 deletions

323
include/wx/rtti.h Normal file
View File

@@ -0,0 +1,323 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/rtti.h
// Purpose: old RTTI macros (use XTI when possible instead)
// Author: Julian Smart
// Modified by: Ron Lee
// Created: 01/02/97
// RCS-ID: $Id: rtti.h 48412 2007-08-27 17:04:02Z FM $
// Copyright: (c) 1997 Julian Smart
// (c) 2001 Ron Lee <ron@debian.org>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_RTTIH__
#define _WX_RTTIH__
#if !wxUSE_EXTENDED_RTTI // XTI system is meant to replace these macros
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/memory.h"
// ----------------------------------------------------------------------------
// forward declarations
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_FWD_BASE wxObject;
class WXDLLIMPEXP_FWD_BASE wxClassInfo;
class WXDLLIMPEXP_FWD_BASE wxHashTable;
class WXDLLIMPEXP_FWD_BASE wxObject;
class WXDLLIMPEXP_FWD_BASE wxPluginLibrary;
class WXDLLIMPEXP_FWD_BASE wxHashTable_Node;
// ----------------------------------------------------------------------------
// wxClassInfo
// ----------------------------------------------------------------------------
typedef wxObject *(*wxObjectConstructorFn)(void);
class WXDLLIMPEXP_BASE wxClassInfo
{
friend class WXDLLIMPEXP_FWD_BASE wxObject;
friend WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name);
public:
wxClassInfo( const wxChar *className,
const wxClassInfo *baseInfo1,
const wxClassInfo *baseInfo2,
int size,
wxObjectConstructorFn ctor )
: m_className(className)
, m_objectSize(size)
, m_objectConstructor(ctor)
, m_baseInfo1(baseInfo1)
, m_baseInfo2(baseInfo2)
, m_next(sm_first)
{
sm_first = this;
Register();
}
~wxClassInfo();
wxObject *CreateObject() const
{ return m_objectConstructor ? (*m_objectConstructor)() : 0; }
bool IsDynamic() const { return (NULL != m_objectConstructor); }
const wxChar *GetClassName() const { return m_className; }
const wxChar *GetBaseClassName1() const
{ return m_baseInfo1 ? m_baseInfo1->GetClassName() : NULL; }
const wxChar *GetBaseClassName2() const
{ return m_baseInfo2 ? m_baseInfo2->GetClassName() : NULL; }
const wxClassInfo *GetBaseClass1() const { return m_baseInfo1; }
const wxClassInfo *GetBaseClass2() const { return m_baseInfo2; }
int GetSize() const { return m_objectSize; }
wxObjectConstructorFn GetConstructor() const
{ return m_objectConstructor; }
static const wxClassInfo *GetFirst() { return sm_first; }
const wxClassInfo *GetNext() const { return m_next; }
static wxClassInfo *FindClass(const wxString& className);
// Climb upwards through inheritance hierarchy.
// Dual inheritance is catered for.
bool IsKindOf(const wxClassInfo *info) const
{
return info != 0 &&
( info == this ||
( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
}
wxDECLARE_CLASS_INFO_ITERATORS()
private:
const wxChar *m_className;
int m_objectSize;
wxObjectConstructorFn m_objectConstructor;
// Pointers to base wxClassInfos
const wxClassInfo *m_baseInfo1;
const wxClassInfo *m_baseInfo2;
// class info object live in a linked list:
// pointers to its head and the next element in it
static wxClassInfo *sm_first;
wxClassInfo *m_next;
static wxHashTable *sm_classTable;
protected:
// registers the class
void Register();
void Unregister();
DECLARE_NO_COPY_CLASS(wxClassInfo)
};
WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
// ----------------------------------------------------------------------------
// Dynamic class macros
// ----------------------------------------------------------------------------
#define wxDECLARE_ABSTRACT_CLASS(name) \
public: \
static wxClassInfo ms_classInfo; \
virtual wxClassInfo *GetClassInfo() const
#define wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
wxDECLARE_NO_ASSIGN_CLASS(name); \
wxDECLARE_DYNAMIC_CLASS(name)
#define wxDECLARE_DYNAMIC_CLASS_NO_COPY(name) \
wxDECLARE_NO_COPY_CLASS(name); \
wxDECLARE_DYNAMIC_CLASS(name)
#define wxDECLARE_DYNAMIC_CLASS(name) \
wxDECLARE_ABSTRACT_CLASS(name); \
static wxObject* wxCreateObject()
#define wxDECLARE_CLASS(name) \
wxDECLARE_DYNAMIC_CLASS(name)
// common part of the macros below
#define wxIMPLEMENT_CLASS_COMMON(name, basename, baseclsinfo2, func) \
wxClassInfo name::ms_classInfo(wxT(#name), \
&basename::ms_classInfo, \
baseclsinfo2, \
(int) sizeof(name), \
func); \
\
wxClassInfo *name::GetClassInfo() const \
{ return &name::ms_classInfo; }
#define wxIMPLEMENT_CLASS_COMMON1(name, basename, func) \
wxIMPLEMENT_CLASS_COMMON(name, basename, NULL, func)
#define wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, func) \
wxIMPLEMENT_CLASS_COMMON(name, basename1, &basename2::ms_classInfo, func)
// -----------------------------------
// for concrete classes
// -----------------------------------
// Single inheritance with one base class
#define wxIMPLEMENT_DYNAMIC_CLASS(name, basename) \
wxIMPLEMENT_CLASS_COMMON1(name, basename, name::wxCreateObject) \
wxObject* name::wxCreateObject() \
{ return new name; }
// Multiple inheritance with two base classes
#define wxIMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, \
name::wxCreateObject) \
wxObject* name::wxCreateObject() \
{ return new name; }
// -----------------------------------
// for abstract classes
// -----------------------------------
// Single inheritance with one base class
#define wxIMPLEMENT_ABSTRACT_CLASS(name, basename) \
wxIMPLEMENT_CLASS_COMMON1(name, basename, NULL)
// Multiple inheritance with two base classes
#define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, NULL)
#define wxIMPLEMENT_CLASS(name, basename) \
wxIMPLEMENT_ABSTRACT_CLASS(name, basename)
#define wxIMPLEMENT_CLASS2(name, basename1, basename2) \
IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
// -----------------------------------
// XTI-compatible macros
// -----------------------------------
#include "wx/flags.h"
// these macros only do something when wxUSE_EXTENDED_RTTI=1
// (and in that case they are defined by xti.h); however to avoid
// to be forced to wrap these macros (in user's source files) with
//
// #if wxUSE_EXTENDED_RTTI
// ...
// #endif
//
// blocks, we define them here as empty.
#define wxEMPTY_PARAMETER_VALUE /**/
#define wxBEGIN_ENUM( e ) wxEMPTY_PARAMETER_VALUE
#define wxENUM_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
#define wxEND_ENUM( e ) wxEMPTY_PARAMETER_VALUE
#define wxIMPLEMENT_SET_STREAMING(SetName,e) wxEMPTY_PARAMETER_VALUE
#define wxBEGIN_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
#define wxFLAGS_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
#define wxEND_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
#define wxCOLLECTION_TYPE_INFO( element, collection ) wxEMPTY_PARAMETER_VALUE
#define wxHANDLER(name,eventClassType) wxEMPTY_PARAMETER_VALUE
#define wxBEGIN_HANDLERS_TABLE(theClass) wxEMPTY_PARAMETER_VALUE
#define wxEND_HANDLERS_TABLE() wxEMPTY_PARAMETER_VALUE
#define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) wxIMPLEMENT_DYNAMIC_CLASS( name, basename )
#define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback ) \
wxEMPTY_PARAMETER_VALUE
#define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) wxEMPTY_PARAMETER_VALUE
#define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
unit, toString, \
fromString ) wxEMPTY_PARAMETER_VALUE
#define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) wxEMPTY_PARAMETER_VALUE
#define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) wxEMPTY_PARAMETER_VALUE
#define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2 )
#define wxCONSTRUCTOR_0(klass) \
wxEMPTY_PARAMETER_VALUE
#define wxCONSTRUCTOR_DUMMY(klass) \
wxEMPTY_PARAMETER_VALUE
#define wxDIRECT_CONSTRUCTOR_0(klass) \
wxEMPTY_PARAMETER_VALUE
#define wxCONSTRUCTOR_1(klass,t0,v0) \
wxEMPTY_PARAMETER_VALUE
#define wxDIRECT_CONSTRUCTOR_1(klass,t0,v0) \
wxEMPTY_PARAMETER_VALUE
#define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
wxEMPTY_PARAMETER_VALUE
#define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
wxEMPTY_PARAMETER_VALUE
#define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
wxEMPTY_PARAMETER_VALUE
#define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
wxEMPTY_PARAMETER_VALUE
#define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
wxEMPTY_PARAMETER_VALUE
#define wxDIRECT_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
wxEMPTY_PARAMETER_VALUE
#define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
wxEMPTY_PARAMETER_VALUE
#define wxDIRECT_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
wxEMPTY_PARAMETER_VALUE
#define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
wxEMPTY_PARAMETER_VALUE
#define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
wxEMPTY_PARAMETER_VALUE
#define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
wxEMPTY_PARAMETER_VALUE
#define wxDIRECT_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
wxEMPTY_PARAMETER_VALUE
#define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
wxEMPTY_PARAMETER_VALUE
#define wxDIRECT_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
wxEMPTY_PARAMETER_VALUE
#define wxSETTER( property, Klass, valueType, setterMethod ) wxEMPTY_PARAMETER_VALUE
#define wxGETTER( property, Klass, valueType, gettermethod ) wxEMPTY_PARAMETER_VALUE
#define wxADDER( property, Klass, valueType, addermethod ) wxEMPTY_PARAMETER_VALUE
#define wxCOLLECTION_GETTER( property, Klass, valueType, gettermethod ) wxEMPTY_PARAMETER_VALUE
#define wxBEGIN_PROPERTIES_TABLE(theClass) wxEMPTY_PARAMETER_VALUE
#define wxEND_PROPERTIES_TABLE() wxEMPTY_PARAMETER_VALUE
#define wxHIDE_PROPERTY( pname ) wxEMPTY_PARAMETER_VALUE
#define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \
wxEMPTY_PARAMETER_VALUE
#define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue, \
pflags, help, group) wxEMPTY_PARAMETER_VALUE
#define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \
wxGETTER( pname, class_t, type, getter ) wxEMPTY_PARAMETER_VALUE
#define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue, \
pflags, help, group) wxEMPTY_PARAMETER_VALUE
#define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter, \
flags, help, group ) wxEMPTY_PARAMETER_VALUE
#define wxREADONLY_PROPERTY_COLLECTION( pname, colltype, addelemtype, getter, \
flags, help, group) wxEMPTY_PARAMETER_VALUE
#define wxEVENT_PROPERTY( name, eventType, eventClass ) wxEMPTY_PARAMETER_VALUE
#define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) wxEMPTY_PARAMETER_VALUE
#define wxIMPLEMENT_PROPERTY(name, type) wxEMPTY_PARAMETER_VALUE
#define wxEMPTY_HANDLERS_TABLE(name) wxEMPTY_PARAMETER_VALUE
#endif // !wxUSE_EXTENDED_RTTI
#endif // _WX_RTTIH__

279
include/wx/variantbase.h Normal file
View File

@@ -0,0 +1,279 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/variantbase.h
// Purpose: wxVariantBase class, a minimal version of wxVariant used by XTI
// Author: Julian Smart
// Modified by: Francesco Montorsi
// Created: 10/09/98
// RCS-ID: $Id: variant.h 44625 2007-03-07 11:35:04Z VZ $
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_VARIANTBASE_H_
#define _WX_VARIANTBASE_H_
#include "wx/defs.h"
#if wxUSE_VARIANT
#include "wx/string.h"
#include "wx/arrstr.h"
#include "wx/cpp.h"
#include <typeinfo>
#if wxUSE_DATETIME
#include "wx/datetime.h"
#endif // wxUSE_DATETIME
#include "wx/iosfwrap.h"
class wxTypeInfo;
class wxObject;
class wxClassInfo;
/*
* wxVariantData stores the actual data in a wxVariant object,
* to allow it to store any type of data.
* Derive from this to provide custom data handling.
*
* NB: To prevent addition of extra vtbl pointer to wxVariantData,
* we don't multiple-inherit from wxObjectRefData. Instead,
* we simply replicate the wxObject ref-counting scheme.
*
* NB: When you construct a wxVariantData, it will have refcount
* of one. Refcount will not be further increased when
* it is passed to wxVariant. This simulates old common
* scenario where wxVariant took ownership of wxVariantData
* passed to it.
* If you create wxVariantData for other reasons than passing
* it to wxVariant, technically you are not required to call
* DecRef() before deleting it.
*
* TODO: in order to replace wxPropertyValue, we would need
* to consider adding constructors that take pointers to C++ variables,
* or removing that functionality from the wxProperty library.
* Essentially wxPropertyValue takes on some of the wxValidator functionality
* by storing pointers and not just actual values, allowing update of C++ data
* to be handled automatically. Perhaps there's another way of doing this without
* overloading wxVariant with unnecessary functionality.
*/
class WXDLLIMPEXP_BASE wxVariantData
{
friend class wxVariantBase;
public:
wxVariantData()
: m_count(1)
{ }
#if wxUSE_STD_IOSTREAM
virtual bool Write(wxSTD ostream& WXUNUSED(str)) const { return false; }
virtual bool Read(wxSTD istream& WXUNUSED(str)) { return false; }
#endif
virtual bool Write(wxString& WXUNUSED(str)) const { return false; }
virtual bool Read(wxString& WXUNUSED(str)) { return false; }
// Override these to provide common functionality
virtual bool Eq(wxVariantData& data) const = 0;
// What type is it? Return a string name.
virtual wxString GetType() const = 0;
// returns the type info of the content
virtual const wxTypeInfo* GetTypeInfo() const = 0;
// If it based on wxObject return the ClassInfo.
virtual wxClassInfo* GetValueClassInfo() { return NULL; }
int GetRefCount() const
{ return m_count; }
void IncRef()
{ m_count++; }
void DecRef()
{
if ( --m_count == 0 )
delete this;
}
protected:
// Protected dtor should make some incompatible code
// break more louder. That is, they should do data->DecRef()
// instead of delete data.
virtual ~wxVariantData() {}
private:
int m_count;
};
template<typename T> class wxVariantDataT : public wxVariantData
{
public:
wxVariantDataT(const T& d) : m_data(d) {}
virtual ~wxVariantDataT() {}
// get a ref to the stored data
T & Get() { return m_data; }
// get a const ref to the stored data
const T & Get() const { return m_data; }
// set the data
void Set(const T& d) { m_data = d; }
// Override these to provide common functionality
virtual bool Eq(wxVariantData& WXUNUSED(data)) const
{ return false; /* FIXME!! */ }
// What type is it? Return a string name.
virtual wxString GetType() const
{ return GetTypeInfo()->GetTypeName(); }
// return a heap allocated duplicate
//virtual wxVariantData* Clone() const { return new wxVariantDataT<T>( Get() ); }
// returns the type info of the contentc
virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ); }
private:
T m_data;
};
/*
* wxVariantBase can store any kind of data, but has some basic types
* built in.
*/
class WXDLLIMPEXP_BASE wxVariantBase
{
public:
wxVariantBase();
wxVariantBase(const wxVariantBase& variant);
wxVariantBase(wxVariantData* data, const wxString& name = wxEmptyString);
template<typename T>
wxVariantBase(const T& data, const wxString& name = wxEmptyString) :
m_data(new wxVariantDataT<T>(data)), m_name(name) {}
virtual ~wxVariantBase();
// generic assignment
void operator= (const wxVariantBase& variant);
// Assignment using data, e.g.
// myVariant = new wxStringVariantData("hello");
void operator= (wxVariantData* variantData);
bool operator== (const wxVariantBase& variant) const;
bool operator!= (const wxVariantBase& variant) const;
// Sets/gets name
inline void SetName(const wxString& name) { m_name = name; }
inline const wxString& GetName() const { return m_name; }
// Tests whether there is data
bool IsNull() const;
// FIXME: used by wxVariantBase code but is nice wording...
bool IsEmpty() const { return IsNull(); }
// For compatibility with wxWidgets <= 2.6, this doesn't increase
// reference count.
wxVariantData* GetData() const { return m_data; }
void SetData(wxVariantData* data) ;
// make a 'clone' of the object
void Ref(const wxVariantBase& clone);
// destroy a reference
void UnRef();
// Make NULL (i.e. delete the data)
void MakeNull();
// write contents to a string (e.g. for debugging)
wxString MakeString() const;
// Delete data and name
void Clear();
// Returns a string representing the type of the variant,
// e.g. "string", "bool", "stringlist", "list", "double", "long"
wxString GetType() const;
bool IsType(const wxString& type) const;
bool IsValueKindOf(const wxClassInfo* type) const;
// FIXME wxXTI methods:
// get the typeinfo of the stored object
const wxTypeInfo* GetTypeInfo() const
{
if (!m_data)
return NULL;
return m_data->GetTypeInfo();
}
// get a ref to the stored data
template<typename T> T& Get(wxTEMPLATED_MEMBER_FIX(T))
{
wxVariantDataT<T> *dataptr =
wx_dynamic_cast(wxVariantDataT<T>*, m_data);
wxASSERT_MSG( dataptr,
wxString::Format(wxT("Cast to %s not possible"), typeid(T).name()) );
return dataptr->Get();
}
// get a const ref to the stored data
template<typename T> const T& Get(wxTEMPLATED_MEMBER_FIX(T)) const
{
const wxVariantDataT<T> *dataptr =
wx_dynamic_cast(const wxVariantDataT<T>*, m_data);
wxASSERT_MSG( dataptr,
wxString::Format(wxT("Cast to %s not possible"), typeid(T).name()) );
return dataptr->Get();
}
template<typename T> bool HasData(wxTEMPLATED_MEMBER_FIX(T)) const
{
const wxVariantDataT<T> *dataptr =
wx_dynamic_cast(const wxVariantDataT<T>*, m_data);
return dataptr != NULL;
}
// returns this value as string
wxString GetAsString() const;
// gets the stored data casted to a wxObject*,
// returning NULL if cast is not possible
wxObject* GetAsObject();
protected:
wxVariantData* m_data;
wxString m_name;
};
#include "wx/dynarray.h"
WX_DECLARE_OBJARRAY_WITH_DECL(wxVariantBase, wxVariantBaseArray, class WXDLLIMPEXP_BASE);
// templated streaming, every type must have their specialization for these methods
template<typename T>
void wxStringReadValue( const wxString &s, T &data );
template<typename T>
void wxStringWriteValue( wxString &s, const T &data);
template<typename T>
void wxToStringConverter( const wxVariantBase &v, wxString &s wxTEMPLATED_FUNCTION_FIX(T)) \
{ wxStringWriteValue( s, v.wxTEMPLATED_MEMBER_CALL(Get, T) ); }
template<typename T>
void wxFromStringConverter( const wxString &s, wxVariantBase &v wxTEMPLATED_FUNCTION_FIX(T)) \
{ T d; wxStringReadValue( s, d ); v = wxVariantBase(d); }
#endif // wxUSE_VARIANT
#endif // _WX_VARIANTBASE_H_

520
include/wx/xtictor.h Normal file
View File

@@ -0,0 +1,520 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/xtictor.h
// Purpose: XTI constructors
// Author: Stefan Csomor
// Modified by: Francesco Montorsi
// Created: 27/07/03
// RCS-ID: $Id: xti.h 47299 2007-07-10 15:58:27Z FM $
// Copyright: (c) 1997 Julian Smart
// (c) 2003 Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _XTICTOR_H_
#define _XTICTOR_H_
#include "wx/defs.h"
#if wxUSE_EXTENDED_RTTI
#include "wx/string.h"
#include "wx/variant.h"
class WXDLLIMPEXP_BASE wxObject;
class WXDLLIMPEXP_BASE wxClassInfo;
class WXDLLIMPEXP_BASE wxDynamicClassInfo;
class WXDLLIMPEXP_BASE wxHashTable;
class WXDLLIMPEXP_BASE wxHashTable_Node;
class WXDLLIMPEXP_BASE wxObjectRefData;
class WXDLLIMPEXP_BASE wxEvent;
class WXDLLIMPEXP_BASE wxEvtHandler;
// ----------------------------------------------------------------------------
// Constructor Bridges
// ----------------------------------------------------------------------------
// A constructor bridge allows to call a ctor with an arbitrary number
// or parameters during runtime
class WXDLLIMPEXP_BASE wxObjectAllocatorAndCreator
{
public:
virtual ~wxObjectAllocatorAndCreator() { }
virtual bool Create(wxObject * &o, wxVariantBase *args) = 0;
};
// a direct constructor bridge calls the operator new for this class and
// passes all params to the constructor. Needed for classes that cannot be
// instantiated using alloc-create semantics
class WXDLLIMPEXP_BASE wxObjectAllocator : public wxObjectAllocatorAndCreator
{
public:
virtual bool Create(wxObject * &o, wxVariantBase *args) = 0;
};
// ----------------------------------------------------------------------------
// Constructor Bridges for all Numbers of Params
// ----------------------------------------------------------------------------
// no params
template<typename Class>
struct wxObjectAllocatorAndCreator_0 : public wxObjectAllocatorAndCreator
{
bool Create(wxObject * &o, wxVariantBase *)
{
Class *obj = wx_dynamic_cast(Class*, o);
return obj->Create();
}
};
struct wxObjectAllocatorAndCreator_Dummy : public wxObjectAllocatorAndCreator
{
bool Create(wxObject *&, wxVariantBase *)
{
return true;
}
};
#define wxCONSTRUCTOR_0(klass) \
wxObjectAllocatorAndCreator_0<klass> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { NULL }; \
const int klass::ms_constructorPropertiesCount = 0;
#define wxCONSTRUCTOR_DUMMY(klass) \
wxObjectAllocatorAndCreator_Dummy constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { NULL }; \
const int klass::ms_constructorPropertiesCount = 0;
// direct constructor version
template<typename Class>
struct wxDirectConstructorBridge_0 : public wxObjectAllocator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
o = new Class( );
return o != NULL;
}
};
#define wxDIRECT_CONSTRUCTOR_0(klass) \
wxDirectConstructorBridge_0<klass> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { NULL }; \
const int klass::ms_constructorPropertiesCount = 0;
// 1 param
template<typename Class, typename T0>
struct wxObjectAllocatorAndCreator_1 : public wxObjectAllocatorAndCreator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
Class *obj = wx_dynamic_cast(Class*, o);
return obj->Create(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0)
);
}
};
#define wxCONSTRUCTOR_1(klass,t0,v0) \
wxObjectAllocatorAndCreator_1<klass,t0> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) }; \
const int klass::ms_constructorPropertiesCount = 1;
// direct constructor version
template<typename Class, typename T0>
struct wxDirectConstructorBridge_1 : public wxObjectAllocator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
o = new Class(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0)
);
return o != NULL;
}
};
#define wxDIRECT_CONSTRUCTOR_1(klass,t0,v0) \
wxDirectConstructorBridge_1<klass,t0,t1> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) }; \
const int klass::ms_constructorPropertiesCount = 1;
// 2 params
template<typename Class,
typename T0, typename T1>
struct wxObjectAllocatorAndCreator_2 : public wxObjectAllocatorAndCreator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
Class *obj = wx_dynamic_cast(Class*, o);
return obj->Create(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1)
);
}
};
#define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
wxObjectAllocatorAndCreator_2<klass,t0,t1> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1) }; \
const int klass::ms_constructorPropertiesCount = 2;
// direct constructor version
template<typename Class,
typename T0, typename T1>
struct wxDirectConstructorBridge_2 : public wxObjectAllocator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
o = new Class(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1)
);
return o != NULL;
}
};
#define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
wxDirectConstructorBridge_2<klass,t0,t1> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1) }; \
const int klass::ms_constructorPropertiesCount = 2;
// 3 params
template<typename Class,
typename T0, typename T1, typename T2>
struct wxObjectAllocatorAndCreator_3 : public wxObjectAllocatorAndCreator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
Class *obj = wx_dynamic_cast(Class*, o);
return obj->Create(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2)
);
}
};
#define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
wxObjectAllocatorAndCreator_3<klass,t0,t1,t2> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), wxT(#v2) }; \
const int klass::ms_constructorPropertiesCount = 3;
// direct constructor version
template<typename Class,
typename T0, typename T1, typename T2>
struct wxDirectConstructorBridge_3 : public wxObjectAllocator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
o = new Class(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2)
);
return o != NULL;
}
};
#define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
wxDirectConstructorBridge_3<klass,t0,t1,t2> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), wxT(#v2) }; \
const int klass::ms_constructorPropertiesCount = 3;
// 4 params
template<typename Class,
typename T0, typename T1, typename T2, typename T3>
struct wxObjectAllocatorAndCreator_4 : public wxObjectAllocatorAndCreator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
Class *obj = wx_dynamic_cast(Class*, o);
return obj->Create(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T3)
);
}
};
#define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
wxObjectAllocatorAndCreator_4<klass,t0,t1,t2,t3> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = \
{ wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3) }; \
const int klass::ms_constructorPropertiesCount = 4;
// direct constructor version
template<typename Class,
typename T0, typename T1, typename T2, typename T3>
struct wxDirectConstructorBridge_4 : public wxObjectAllocator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
o = new Class(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T3)
);
return o != NULL;
}
};
#define wxDIRECT_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
wxDirectConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = \
{ wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3) }; \
const int klass::ms_constructorPropertiesCount = 4;
// 5 params
template<typename Class,
typename T0, typename T1, typename T2, typename T3, typename T4>
struct wxObjectAllocatorAndCreator_5 : public wxObjectAllocatorAndCreator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
Class *obj = wx_dynamic_cast(Class*, o);
return obj->Create(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T3),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T4)
);
}
};
#define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
wxObjectAllocatorAndCreator_5<klass,t0,t1,t2,t3,t4> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = \
{ wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4) }; \
const int klass::ms_constructorPropertiesCount = 5;
// direct constructor version
template<typename Class,
typename T0, typename T1, typename T2, typename T3, typename T4>
struct wxDirectConstructorBridge_5 : public wxObjectAllocator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
o = new Class(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T3),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T4)
);
return o != NULL;
}
};
#define wxDIRECT_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
wxDirectConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = \
{ wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4) }; \
const int klass::ms_constructorPropertiesCount = 5;
// 6 params
template<typename Class,
typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
struct wxObjectAllocatorAndCreator_6 : public wxObjectAllocatorAndCreator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
Class *obj = wx_dynamic_cast(Class*, o);
return obj->Create(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T3),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T4),
args[5].wxTEMPLATED_MEMBER_CALL(Get, T5)
);
}
};
#define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
wxObjectAllocatorAndCreator_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = \
{ wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5) }; \
const int klass::ms_constructorPropertiesCount = 6;
// direct constructor version
template<typename Class,
typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
struct wxDirectConstructorBridge_6 : public wxObjectAllocator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
o = new Class(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T3),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T4),
args[5].wxTEMPLATED_MEMBER_CALL(Get, T5)
);
return o != NULL;
}
};
#define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), \
wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5) }; \
const int klass::ms_constructorPropertiesCount = 6;
// 7 params
template<typename Class,
typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct wxObjectAllocatorAndCreator_7 : public wxObjectAllocatorAndCreator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
Class *obj = wx_dynamic_cast(Class*, o);
return obj->Create(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T3),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T4),
args[5].wxTEMPLATED_MEMBER_CALL(Get, T5),
args[6].wxTEMPLATED_MEMBER_CALL(Get, T6)
);
}
};
#define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
wxObjectAllocatorAndCreator_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), \
wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6) }; \
const int klass::ms_constructorPropertiesCount = 7;
// direct constructor version
template<typename Class,
typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct wxDirectConstructorBridge_7 : public wxObjectAllocator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
o = new Class(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T3),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T4),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T5),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T6)
);
return o != NULL;
}
};
#define wxDIRECT_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
wxDirectConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = \
{ wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6) }; \
const int klass::ms_constructorPropertiesCount = 7;
// 8 params
template<typename Class,
typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, \
typename T6, typename T7>
struct wxObjectAllocatorAndCreator_8 : public wxObjectAllocatorAndCreator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
Class *obj = wx_dynamic_cast(Class*, o);
return obj->Create(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T3),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T4),
args[5].wxTEMPLATED_MEMBER_CALL(Get, T5),
args[6].wxTEMPLATED_MEMBER_CALL(Get, T6),
args[7].wxTEMPLATED_MEMBER_CALL(Get, T7)
);
}
};
#define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
wxObjectAllocatorAndCreator_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = \
{ wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6), wxT(#v7) }; \
const int klass::ms_constructorPropertiesCount = 8;
// direct constructor version
template<typename Class,
typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, \
typename T6, typename T7>
struct wxDirectConstructorBridge_8 : public wxObjectAllocator
{
bool Create(wxObject * &o, wxVariantBase *args)
{
o = new Class(
args[0].wxTEMPLATED_MEMBER_CALL(Get, T0),
args[1].wxTEMPLATED_MEMBER_CALL(Get, T1),
args[2].wxTEMPLATED_MEMBER_CALL(Get, T2),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T3),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T4),
args[3].wxTEMPLATED_MEMBER_CALL(Get, T5),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T6),
args[4].wxTEMPLATED_MEMBER_CALL(Get, T7)
);
return o != NULL;
}
};
#define wxDIRECT_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
wxDirectConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass; \
wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
const wxChar *klass::ms_constructorProperties[] = \
{ wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6), wxT(#v7) }; \
const int klass::ms_constructorPropertiesCount = 8;
#endif // wxUSE_EXTENDED_RTTI
#endif // _XTICTOR_H_

110
include/wx/xtihandler.h Normal file
View File

@@ -0,0 +1,110 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/xtihandler.h
// Purpose: XTI handlers
// Author: Stefan Csomor
// Modified by: Francesco Montorsi
// Created: 27/07/03
// RCS-ID: $Id: xti.h 47299 2007-07-10 15:58:27Z FM $
// Copyright: (c) 1997 Julian Smart
// (c) 2003 Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _XTIHANDLER_H_
#define _XTIHANDLER_H_
#include "wx/defs.h"
#if wxUSE_EXTENDED_RTTI
#include "wx/string.h"
class WXDLLIMPEXP_BASE wxObject;
class WXDLLIMPEXP_BASE wxClassInfo;
class WXDLLIMPEXP_BASE wxDynamicClassInfo;
class WXDLLIMPEXP_BASE wxHashTable;
class WXDLLIMPEXP_BASE wxHashTable_Node;
class WXDLLIMPEXP_BASE wxObjectRefData;
class WXDLLIMPEXP_BASE wxEvent;
class WXDLLIMPEXP_BASE wxEvtHandler;
typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
// ----------------------------------------------------------------------------
// Handler Info
//
// this describes an event sink
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxHandlerInfo
{
friend class WXDLLIMPEXP_BASE wxDynamicClassInfo;
public:
wxHandlerInfo(wxHandlerInfo* &iter,
wxClassInfo* itsClass,
const wxString& name,
wxObjectEventFunction address,
const wxClassInfo* eventClassInfo) :
m_eventFunction(address),
m_name(name),
m_eventClassInfo(eventClassInfo),
m_itsClass(itsClass)
{
Insert(iter);
}
~wxHandlerInfo()
{ Remove(); }
// return the name of this handler
const wxString& GetName() const { return m_name; }
// return the class info of the event
const wxClassInfo *GetEventClassInfo() const { return m_eventClassInfo; }
// get the handler function pointer
wxObjectEventFunction GetEventFunction() const { return m_eventFunction; }
// returns NULL if this is the last handler of this class
wxHandlerInfo* GetNext() const { return m_next; }
// return the class this property is declared in
const wxClassInfo* GetDeclaringClass() const { return m_itsClass; }
private:
// inserts this handler at the end of the linked chain which begins
// with "iter" handler.
void Insert(wxHandlerInfo* &iter);
// removes this handler from the linked chain of the m_itsClass handlers.
void Remove();
wxObjectEventFunction m_eventFunction;
wxString m_name;
const wxClassInfo* m_eventClassInfo;
wxHandlerInfo* m_next;
wxClassInfo* m_itsClass;
};
#define wxHANDLER(name,eventClassType) \
static wxHandlerInfo _handlerInfo##name( first, class_t::GetClassInfoStatic(), \
wxT(#name), (wxObjectEventFunction) (wxEventFunction) &name, \
CLASSINFO( eventClassType ) );
#define wxBEGIN_HANDLERS_TABLE(theClass) \
wxHandlerInfo *theClass::GetHandlersStatic() \
{ \
typedef theClass class_t; \
static wxHandlerInfo* first = NULL;
#define wxEND_HANDLERS_TABLE() \
return first; }
#define wxEMPTY_HANDLERS_TABLE(theClass) \
wxBEGIN_HANDLERS_TABLE(theClass) \
wxEND_HANDLERS_TABLE()
#endif // wxUSE_EXTENDED_RTTI
#endif // _XTIHANDLER_H_

597
include/wx/xtiprop.h Normal file
View File

@@ -0,0 +1,597 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/xtiprop.h
// Purpose: XTI properties
// Author: Stefan Csomor
// Modified by: Francesco Montorsi
// Created: 27/07/03
// RCS-ID: $Id: xti.h 47299 2007-07-10 15:58:27Z FM $
// Copyright: (c) 1997 Julian Smart
// (c) 2003 Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _XTIPROP_H_
#define _XTIPROP_H_
#include "wx/defs.h"
#if wxUSE_EXTENDED_RTTI
#include "wx/string.h"
#include "wx/variant.h"
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/xtitypes.h"
class WXDLLIMPEXP_BASE wxObject;
class WXDLLIMPEXP_BASE wxClassInfo;
class WXDLLIMPEXP_BASE wxDynamicClassInfo;
class WXDLLIMPEXP_BASE wxHashTable;
class WXDLLIMPEXP_BASE wxHashTable_Node;
class WXDLLIMPEXP_BASE wxObjectRefData;
class WXDLLIMPEXP_BASE wxEvent;
class WXDLLIMPEXP_BASE wxEvtHandler;
// ----------------------------------------------------------------------------
// Property Accessors
//
// wxPropertySetter/Getter/CollectionGetter/CollectionAdder are all property
// accessors which are managed by wxPropertyAccessor class which in turn is
// handled by wxPropertyInfo.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxPropertySetter
{
public:
wxPropertySetter( const wxString name ) { m_name = name; }
virtual ~wxPropertySetter() {}
virtual void Set( wxObject *object, const wxVariantBase &variantValue ) const = 0;
const wxString& GetName() const { return m_name; }
private:
wxString m_name;
};
class WXDLLIMPEXP_BASE wxPropertyGetter
{
public:
wxPropertyGetter( const wxString name ) { m_name = name; }
virtual ~wxPropertyGetter() {}
virtual void Get( const wxObject *object, wxVariantBase& result) const = 0;
const wxString& GetName() const { return m_name; }
private:
wxString m_name;
};
class WXDLLIMPEXP_BASE wxPropertyCollectionGetter
{
public:
wxPropertyCollectionGetter( const wxString name ) { m_name = name; }
virtual ~wxPropertyCollectionGetter() {}
virtual void Get( const wxObject *object, wxVariantBaseArray& result) const = 0;
const wxString& GetName() const { return m_name; }
private:
wxString m_name;
};
template<typename coll_t> void WXDLLIMPEXP_BASE \
wxCollectionToVariantArray( const coll_t& coll, wxVariantBaseArray& result );
class WXDLLIMPEXP_BASE wxPropertyCollectionAdder
{
public:
wxPropertyCollectionAdder( const wxString name ) { m_name = name; }
virtual ~wxPropertyCollectionAdder() {}
virtual void Add( wxObject *object, const wxVariantBase &variantValue ) const= 0;
const wxString& GetName() const { return m_name; }
private:
wxString m_name;
};
#define wxPROPERTY_SETTER( property, Klass, valueType, setterMethod ) \
class wxPropertySetter##property : public wxPropertySetter \
{ \
public: \
wxINFUNC_CLASS_TYPE_FIX(Klass) \
wxPropertySetter##property() : wxPropertySetter( wxT(#setterMethod) ) {} \
virtual ~wxPropertySetter##property() {} \
\
void Set( wxObject *object, const wxVariantBase &variantValue ) const \
{ \
Klass *obj = dynamic_cast<Klass*>(object); \
if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
obj->setterMethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get, valueType)); \
else \
obj->setterMethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get, valueType*)); \
} \
};
#define wxPROPERTY_GETTER( property, Klass, valueType, gettermethod ) \
class wxPropertyGetter##property : public wxPropertyGetter \
{ \
public: \
wxINFUNC_CLASS_TYPE_FIX(Klass) \
wxPropertyGetter##property() : wxPropertyGetter( wxT(#gettermethod) ) {} \
virtual ~wxPropertyGetter##property() {} \
\
void Get( const wxObject *object, wxVariantBase &result) const \
{ \
const Klass *obj = dynamic_cast<const Klass*>(object); \
result = wxVariantBase( obj->gettermethod() ); \
} \
};
#define wxPROPERTY_COLLECTION_ADDER( property, Klass, valueType, addermethod ) \
class wxPropertyCollectionAdder##property : public wxPropertyCollectionAdder \
{ \
public: \
wxINFUNC_CLASS_TYPE_FIX(Klass) \
wxPropertyCollectionAdder##property() : wxPropertyCollectionAdder( wxT(#addermethod) ) {} \
virtual ~wxPropertyCollectionAdder##property() {} \
\
void Add( wxObject *object, const wxVariantBase &variantValue ) const \
{ \
Klass *obj = dynamic_cast<Klass*>(object); \
if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
obj->addermethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get, valueType)); \
else \
obj->addermethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get, valueType*)); \
} \
};
#define wxPROPERTY_COLLECTION_GETTER( property, Klass, valueType, gettermethod ) \
class wxPropertyCollectionGetter##property : public wxPropertyCollectionGetter \
{ \
public: \
wxINFUNC_CLASS_TYPE_FIX(Klass) \
wxPropertyCollectionGetter##property() : wxPropertyCollectionGetter( wxT(#gettermethod) ) {} \
virtual ~wxPropertyCollectionGetter##property() {} \
\
void Get( const wxObject *object, wxVariantBaseArray &result) const \
{ \
const Klass *obj = dynamic_cast<const Klass*>(object); \
wxCollectionToVariantArray( obj->gettermethod(), result ); \
} \
};
class WXDLLIMPEXP_BASE wxPropertyAccessor
{
public:
wxPropertyAccessor( wxPropertySetter *setter, wxPropertyGetter *getter,
wxPropertyCollectionAdder *adder, wxPropertyCollectionGetter *collectionGetter )
{ m_setter = setter; m_getter = getter; m_adder = adder;
m_collectionGetter = collectionGetter; }
virtual ~wxPropertyAccessor() {}
// Setting a simple property (non-collection)
virtual void SetProperty(wxObject *object, const wxVariantBase &value) const
{
if ( m_setter )
m_setter->Set( object, value );
else
wxLogError( _("SetProperty called w/o valid setter") );
}
// Getting a simple property (non-collection)
virtual void GetProperty(const wxObject *object, wxVariantBase &result) const
{
if ( m_getter )
m_getter->Get( object, result );
else
wxLogError( _("GetProperty called w/o valid getter") );
}
// Adding an element to a collection property
virtual void AddToPropertyCollection(wxObject *object, const wxVariantBase &value) const
{
if ( m_adder )
m_adder->Add( object, value );
else
wxLogError( _("AddToPropertyCollection called w/o valid adder") );
}
// Getting a collection property
virtual void GetPropertyCollection( const wxObject *obj, wxVariantBaseArray &result) const
{
if ( m_collectionGetter )
m_collectionGetter->Get( obj, result);
else
wxLogError( _("GetPropertyCollection called w/o valid collection getter") );
}
virtual bool HasSetter() const { return m_setter != NULL; }
virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL; }
virtual bool HasGetter() const { return m_getter != NULL; }
virtual bool HasAdder() const { return m_adder != NULL; }
virtual const wxString& GetCollectionGetterName() const
{ return m_collectionGetter->GetName(); }
virtual const wxString& GetGetterName() const
{ return m_getter->GetName(); }
virtual const wxString& GetSetterName() const
{ return m_setter->GetName(); }
virtual const wxString& GetAdderName() const
{ return m_adder->GetName(); }
protected:
wxPropertySetter *m_setter;
wxPropertyCollectionAdder *m_adder;
wxPropertyGetter *m_getter;
wxPropertyCollectionGetter* m_collectionGetter;
};
class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
{
public:
wxGenericPropertyAccessor( const wxString &propName );
virtual ~wxGenericPropertyAccessor();
void RenameProperty( const wxString& WXUNUSED_UNLESS_DEBUG(oldName),
const wxString& newName )
{
wxASSERT( oldName == m_propertyName ); m_propertyName = newName;
}
virtual bool HasSetter() const { return true; }
virtual bool HasGetter() const { return true; }
virtual bool HasAdder() const { return false; }
virtual bool HasCollectionGetter() const { return false; }
virtual const wxString& GetGetterName() const
{ return m_getterName; }
virtual const wxString& GetSetterName() const
{ return m_setterName; }
virtual void SetProperty(wxObject *object, const wxVariantBase &value) const;
virtual void GetProperty(const wxObject *object, wxVariantBase &value) const;
// Adding an element to a collection property
virtual void AddToPropertyCollection(wxObject *WXUNUSED(object),
const wxVariantBase &WXUNUSED(value)) const
{
wxLogError( _("AddToPropertyCollection called on a generic accessor") );
}
// Getting a collection property
virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj),
wxVariantBaseArray &WXUNUSED(result)) const
{
wxLogError ( _("GetPropertyCollection called on a generic accessor") );
}
private:
struct wxGenericPropertyAccessorInternal;
wxGenericPropertyAccessorInternal* m_data;
wxString m_propertyName;
wxString m_setterName;
wxString m_getterName;
};
typedef long wxPropertyInfoFlags;
enum
{
// will be removed in future releases
wxPROP_DEPRECATED = 0x00000001,
// object graph property, will be streamed with priority (after constructor properties)
wxPROP_OBJECT_GRAPH = 0x00000002,
// this will only be streamed out and in as enum/set, the internal representation
// is still a long
wxPROP_ENUM_STORE_LONG = 0x00000004,
// don't stream out this property, needed eg to avoid streaming out children
// that are always created by their parents
wxPROP_DONT_STREAM = 0x00000008
};
// ----------------------------------------------------------------------------
// Property Support
//
// wxPropertyInfo is used to inquire of the property by name. It doesn't
// provide access to the property, only information about it. If you
// want access, look at wxPropertyAccessor.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxPropertyInfo
{
friend class WXDLLIMPEXP_BASE wxDynamicClassInfo;
public:
wxPropertyInfo(wxPropertyInfo* &iter,
wxClassInfo* itsClass,
const wxString& name,
const wxString& typeName,
wxPropertyAccessor *accessor,
wxVariantBase dv,
wxPropertyInfoFlags flags = 0,
const wxString& helpString = wxEmptyString,
const wxString& groupString = wxEmptyString) :
m_itsClass(itsClass),
m_name(name),
m_typeInfo(NULL),
m_typeName(typeName),
m_collectionElementTypeInfo(NULL),
m_accessor(accessor),
m_defaultValue(dv),
m_flags(flags),
m_helpString(helpString),
m_groupString(groupString)
{
Insert(iter);
}
#if wxUSE_UNICODE
wxPropertyInfo(wxPropertyInfo* &iter,
wxClassInfo* itsClass,
const wxString& name,
const char* typeName,
wxPropertyAccessor *accessor,
wxVariantBase dv,
wxPropertyInfoFlags flags = 0,
const wxString& helpString = wxEmptyString,
const wxString& groupString = wxEmptyString) :
m_itsClass(itsClass),
m_name(name),
m_typeInfo(NULL),
m_typeName(wxString::FromAscii(typeName)),
m_collectionElementTypeInfo(NULL),
m_accessor(accessor),
m_defaultValue(dv),
m_flags(flags),
m_helpString(helpString),
m_groupString(groupString)
{
Insert(iter);
}
#endif
wxPropertyInfo(wxPropertyInfo* &iter,
wxClassInfo* itsClass,
const wxString& name,
wxEventSourceTypeInfo* type,
wxPropertyAccessor *accessor,
wxVariantBase dv,
wxPropertyInfoFlags flags = 0,
const wxString& helpString = wxEmptyString,
const wxString& groupString = wxEmptyString) :
m_itsClass(itsClass),
m_name(name),
m_typeInfo(type),
m_collectionElementTypeInfo(NULL),
m_accessor(accessor),
m_defaultValue(dv),
m_flags(flags),
m_helpString(helpString),
m_groupString(groupString)
{
Insert(iter);
}
wxPropertyInfo(wxPropertyInfo* &iter,
wxClassInfo* itsClass, const wxString& name,
const wxString& collectionTypeName,
const wxString& elementTypeName,
wxPropertyAccessor *accessor,
wxPropertyInfoFlags flags = 0,
const wxString& helpString = wxEmptyString,
const wxString& groupString = wxEmptyString) :
m_itsClass(itsClass),
m_name(name),
m_typeInfo(NULL),
m_typeName(collectionTypeName),
m_collectionElementTypeInfo(NULL),
m_collectionElementTypeName(elementTypeName),
m_accessor(accessor),
m_flags(flags),
m_helpString(helpString),
m_groupString(groupString)
{
Insert(iter);
}
#if wxUSE_UNICODE
wxPropertyInfo(wxPropertyInfo* &iter,
wxClassInfo* itsClass, const wxString& name,
const char* collectionTypeName,
const char* elementTypeName,
wxPropertyAccessor *accessor,
wxPropertyInfoFlags flags = 0,
const wxString& helpString = wxEmptyString,
const wxString& groupString = wxEmptyString) :
m_itsClass(itsClass),
m_name(name),
m_typeInfo(NULL),
m_typeName(wxString::FromAscii(collectionTypeName)),
m_collectionElementTypeInfo(NULL),
m_collectionElementTypeName(wxString::FromAscii(elementTypeName)),
m_accessor(accessor),
m_flags(flags),
m_helpString(helpString),
m_groupString(groupString)
{
Insert(iter);
}
#endif
~wxPropertyInfo()
{ Remove(); }
// return the class this property is declared in
const wxClassInfo* GetDeclaringClass() const { return m_itsClass; }
// return the name of this property
const wxString& GetName() const { return m_name; }
// returns the flags of this property
wxPropertyInfoFlags GetFlags() const { return m_flags; }
// returns the short help string of this property
const wxString& GetHelpString() const { return m_helpString; }
// returns the group string of this property
const wxString& GetGroupString() const { return m_groupString; }
// return the element type info of this property (for collections, otherwise NULL)
const wxTypeInfo * GetCollectionElementTypeInfo() const
{
if ( m_collectionElementTypeInfo == NULL )
m_collectionElementTypeInfo = wxTypeInfo::FindType(m_collectionElementTypeName);
return m_collectionElementTypeInfo;
}
// return the type info of this property
const wxTypeInfo * GetTypeInfo() const
{
if ( m_typeInfo == NULL )
m_typeInfo = wxTypeInfo::FindType(m_typeName);
return m_typeInfo;
}
// return the accessor for this property
wxPropertyAccessor* GetAccessor() const { return m_accessor; }
// returns NULL if this is the last property of this class
wxPropertyInfo* GetNext() const { return m_next; }
// returns the default value of this property, its kind may be wxT_VOID if it is not valid
wxVariantBase GetDefaultValue() const { return m_defaultValue; }
private:
// inserts this property at the end of the linked chain which begins
// with "iter" property.
void Insert(wxPropertyInfo* &iter);
// removes this property from the linked chain of the m_itsClass properties.
void Remove();
wxClassInfo* m_itsClass;
wxString m_name;
mutable wxTypeInfo* m_typeInfo;
wxString m_typeName;
mutable wxTypeInfo* m_collectionElementTypeInfo;
wxString m_collectionElementTypeName;
wxPropertyAccessor* m_accessor;
wxVariantBase m_defaultValue;
wxPropertyInfoFlags m_flags;
wxString m_helpString;
wxString m_groupString;
wxPropertyInfo* m_next;
// FIXME: what's this comment about??
// string representation of the default value
// to be assigned by the designer to the property
// when the component is dropped on the container.
};
WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo*, wxPropertyInfoMap,
class WXDLLIMPEXP_BASE );
#define wxBEGIN_PROPERTIES_TABLE(theClass) \
wxPropertyInfo *theClass::GetPropertiesStatic() \
{ \
typedef theClass class_t; \
static wxPropertyInfo* first = NULL;
#define wxEND_PROPERTIES_TABLE() \
return first; }
#define wxHIDE_PROPERTY( pname ) \
static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
wxT(#pname), typeid(void).name(), NULL, wxVariantBase(), wxPROP_DONT_STREAM, \
wxEmptyString, wxEmptyString );
#define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \
wxPROPERTY_SETTER( pname, class_t, type, setter ) \
static wxPropertySetter##pname _setter##pname; \
wxPROPERTY_GETTER( pname, class_t, type, getter ) \
static wxPropertyGetter##pname _getter##pname; \
static wxPropertyAccessor _accessor##pname( &_setter##pname, \
&_getter##pname, NULL, NULL ); \
static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
wxT(#pname), typeid(type).name(), &_accessor##pname, \
wxVariantBase(defaultValue), flags, group, help );
#define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue, \
pflags, help, group) \
wxPROPERTY_SETTER( pname, class_t, type, setter ) \
static wxPropertySetter##pname _setter##pname; \
wxPROPERTY_GETTER( pname, class_t, type, getter ) \
static wxPropertyGetter##pname _getter##pname; \
static wxPropertyAccessor _accessor##pname( &_setter##pname, \
&_getter##pname, NULL, NULL ); \
static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
wxT(#pname), typeid(flags).name(), &_accessor##pname, \
wxVariantBase(defaultValue), wxPROP_ENUM_STORE_LONG | pflags, help, group );
#define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \
wxPROPERTY_GETTER( pname, class_t, type, getter ) \
static wxPropertyGetter##pname _getter##pname; \
static wxPropertyAccessor _accessor##pname( NULL, &_getter##pname, NULL, NULL ); \
static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
wxT(#pname), typeid(type).name(),&_accessor##pname, \
wxVariantBase(defaultValue), flags, help, group );
#define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue, \
pflags, help, group) \
wxPROPERTY_GETTER( pname, class_t, type, getter ) \
static wxPropertyGetter##pname _getter##pname; \
static wxPropertyAccessor _accessor##pname( NULL, &_getter##pname, NULL, NULL ); \
static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
wxT(#pname), typeid(flags).name(),&_accessor##pname, \
wxVariantBase(defaultValue), wxPROP_ENUM_STORE_LONG | pflags, help, group );
#define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter, \
flags, help, group ) \
wxPROPERTY_COLLECTION_ADDER( pname, class_t, addelemtype, adder ) \
static wxPropertyCollectionAdder##pname _adder##pname; \
wxPROPERTY_COLLECTION_GETTER( pname, class_t, colltype, getter ) \
static wxPropertyCollectionGetter##pname _collectionGetter##pname; \
static wxPropertyAccessor _accessor##pname( NULL, NULL,&_adder##pname, \
&_collectionGetter##pname ); \
static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
wxT(#pname), typeid(colltype).name(),typeid(addelemtype).name(), \
&_accessor##pname, flags, help, group );
#define wxREADONLY_PROPERTY_COLLECTION( pname, colltype, addelemtype, getter, \
flags, help, group) \
wxPROPERTY_COLLECTION_GETTER( pname, class_t, colltype, getter ) \
static wxPropertyCollectionGetter##pname _collectionGetter##pname; \
static wxPropertyAccessor _accessor##pname( NULL, NULL, NULL, \
&_collectionGetter##pname ); \
static wxPropertyInfo _propertyInfo##pname( first,class_t::GetClassInfoStatic(), \
wxT(#pname), typeid(colltype).name(),typeid(addelemtype).name(), \
&_accessor##pname, flags, help, group );
#define wxEVENT_PROPERTY( name, eventType, eventClass ) \
static wxEventSourceTypeInfo _typeInfo##name( eventType, CLASSINFO( eventClass ) ); \
static wxPropertyInfo _propertyInfo##name( first,class_t::GetClassInfoStatic(), \
wxT(#name), &_typeInfo##name, NULL, wxVariantBase() );
#define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) \
static wxEventSourceTypeInfo _typeInfo##name( eventType, lastEventType, \
CLASSINFO( eventClass ) ); \
static wxPropertyInfo _propertyInfo##name( first, class_t::GetClassInfoStatic(), \
wxT(#name), &_typeInfo##name, NULL, wxVariantBase() );
// ----------------------------------------------------------------------------
// Implementation Helper for Simple Properties
// ----------------------------------------------------------------------------
#define wxIMPLEMENT_PROPERTY(name, type) \
private: \
type m_##name; \
public: \
void Set##name( type const & p) { m_##name = p; } \
type const & Get##name() const { return m_##name; }
#endif // wxUSE_EXTENDED_RTTI
#endif // _XTIPROP_H_

581
include/wx/xtitypes.h Normal file
View File

@@ -0,0 +1,581 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/xtitypes.h
// Purpose: enum, set, basic types support
// Author: Stefan Csomor
// Modified by: Francesco Montorsi
// Created: 27/07/03
// RCS-ID: $Id: xti.h 47299 2007-07-10 15:58:27Z FM $
// Copyright: (c) 1997 Julian Smart
// (c) 2003 Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _XTITYPES_H_
#define _XTITYPES_H_
#include "wx/defs.h"
#if wxUSE_EXTENDED_RTTI
#include "wx/string.h"
#include "wx/hashmap.h"
#include "wx/arrstr.h"
#include "wx/flags.h"
#include "wx/intl.h"
#include "wx/log.h"
#include <typeinfo>
class WXDLLIMPEXP_BASE wxClassInfo;
// ----------------------------------------------------------------------------
// Enum Support
//
// In the header files XTI requires no change from pure c++ code, however in the
// implementation, an enum needs to be enumerated eg:
//
// wxBEGIN_ENUM( wxFlavor )
// wxENUM_MEMBER( Vanilla )
// wxENUM_MEMBER( Chocolate )
// wxENUM_MEMBER( Strawberry )
// wxEND_ENUM( wxFlavor )
// ----------------------------------------------------------------------------
struct WXDLLIMPEXP_BASE wxEnumMemberData
{
const wxChar* m_name;
int m_value;
};
class WXDLLIMPEXP_BASE wxEnumData
{
public:
wxEnumData( wxEnumMemberData* data );
// returns true if the member has been found and sets the int value
// pointed to accordingly (if ptr != null )
// if not found returns false, value left unchanged
bool HasEnumMemberValue( const wxChar *name, int *value = NULL ) const;
// returns the value of the member, if not found in debug mode an
// assert is issued, in release 0 is returned
int GetEnumMemberValue(const wxChar *name ) const;
// returns the name of the enum member having the passed in value
// returns an emtpy string if not found
const wxChar *GetEnumMemberName(int value) const;
// returns the number of members in this enum
int GetEnumCount() const { return m_count; }
// returns the value of the nth member
int GetEnumMemberValueByIndex( int n ) const;
// returns the value of the nth member
const wxChar *GetEnumMemberNameByIndex( int n ) const;
private:
wxEnumMemberData *m_members;
int m_count;
};
#define wxBEGIN_ENUM( e ) \
wxEnumMemberData s_enumDataMembers##e[] = {
#define wxENUM_MEMBER( v ) { wxT(#v), v },
#define wxEND_ENUM( e ) \
{ NULL, 0 } }; \
wxEnumData s_enumData##e( s_enumDataMembers##e ); \
wxEnumData *wxGetEnumData(e) { return &s_enumData##e; } \
template<> void wxStringReadValue(const wxString& s, e &data ) \
{ data = (e) s_enumData##e.GetEnumMemberValue(s); } \
template<> void wxStringWriteValue(wxString &s, const e &data ) \
{ s = s_enumData##e.GetEnumMemberName((int)data); } \
void FromLong##e( long data, wxVariantBase& result ) \
{ result = wxVariantBase((e)data); } \
void ToLong##e( const wxVariantBase& data, long &result ) \
{ result = (long) data.wxTEMPLATED_MEMBER_CALL(Get, e); } \
\
wxTO_STRING_IMP( e ) \
wxFROM_STRING_IMP( e ) \
wxEnumTypeInfo s_typeInfo##e(wxT_ENUM, &s_enumData##e, \
&wxTO_STRING( e ), &wxFROM_STRING( e ), &ToLong##e, \
&FromLong##e, typeid(e).name() );
// ----------------------------------------------------------------------------
// Set Support
//
// in the header :
//
// enum wxFlavor
// {
// Vanilla,
// Chocolate,
// Strawberry,
// };
//
// typedef wxBitset<wxFlavor> wxCoupe;
//
// in the implementation file :
//
// wxBEGIN_ENUM( wxFlavor )
// wxENUM_MEMBER( Vanilla )
// wxENUM_MEMBER( Chocolate )
// wxENUM_MEMBER( Strawberry )
// wxEND_ENUM( wxFlavor )
//
// wxIMPLEMENT_SET_STREAMING( wxCoupe, wxFlavor )
//
// implementation note: no partial specialization for streaming, but a delegation
// to a different class
//
// ----------------------------------------------------------------------------
// in order to remove dependancy on string tokenizer
void WXDLLIMPEXP_BASE wxSetStringToArray( const wxString &s, wxArrayString &array );
template<typename e>
void wxSetFromString(const wxString &s, wxBitset<e> &data )
{
wxEnumData* edata = wxGetEnumData((e) 0);
data.reset();
wxArrayString array;
wxSetStringToArray( s, array );
wxString flag;
for ( int i = 0; i < array.Count(); ++i )
{
flag = array[i];
int ivalue;
if ( edata->HasEnumMemberValue( flag, &ivalue ) )
{
data.set( (e) ivalue );
}
}
}
template<typename e>
void wxSetToString( wxString &s, const wxBitset<e> &data )
{
wxEnumData* edata = wxGetEnumData((e) 0);
int count = edata->GetEnumCount();
int i;
s.Clear();
for ( i = 0; i < count; i++ )
{
e value = (e) edata->GetEnumMemberValueByIndex(i);
if ( data.test( value ) )
{
// this could also be done by the templated calls
if ( !s.empty() )
s += wxT("|");
s += edata->GetEnumMemberNameByIndex(i);
}
}
}
#define wxIMPLEMENT_SET_STREAMING(SetName,e) \
template<> void wxStringReadValue(const wxString &s, wxBitset<e> &data ) \
{ wxSetFromString( s, data ); } \
template<> void wxStringWriteValue( wxString &s, const wxBitset<e> &data ) \
{ wxSetToString( s, data ); } \
void FromLong##SetName( long data, wxVariantBase& result ) \
{ result = wxVariantBase(SetName((unsigned long)data)); } \
void ToLong##SetName( const wxVariantBase& data, long &result ) \
{ result = (long) data.wxTEMPLATED_MEMBER_CALL(Get, SetName).to_ulong(); } \
wxTO_STRING_IMP( SetName ) \
wxFROM_STRING_IMP( SetName ) \
wxEnumTypeInfo s_typeInfo##SetName(wxT_SET, &s_enumData##e, \
&wxTO_STRING( SetName ), &wxFROM_STRING( SetName ), \
&ToLong##SetName, &FromLong##SetName, typeid(SetName).name() );
template<typename e>
void wxFlagsFromString(const wxString &s, e &data )
{
wxEnumData* edata = wxGetEnumData((e*) 0);
data.m_data = 0;
wxArrayString array;
wxSetStringToArray( s, array );
wxString flag;
for ( size_t i = 0; i < array.Count(); ++i )
{
flag = array[i];
int ivalue;
if ( edata->HasEnumMemberValue( flag, &ivalue ) )
{
data.m_data |= ivalue;
}
}
}
template<typename e>
void wxFlagsToString( wxString &s, const e& data )
{
wxEnumData* edata = wxGetEnumData((e*) 0);
int count = edata->GetEnumCount();
int i;
s.Clear();
long dataValue = data.m_data;
for ( i = 0; i < count; i++ )
{
int value = edata->GetEnumMemberValueByIndex(i);
// make this to allow for multi-bit constants to work
if ( value && ( dataValue & value ) == value )
{
// clear the flags we just set
dataValue &= ~value;
// this could also be done by the templated calls
if ( !s.empty() )
s +=wxT("|");
s += edata->GetEnumMemberNameByIndex(i);
}
}
}
#define wxBEGIN_FLAGS( e ) \
wxEnumMemberData s_enumDataMembers##e[] = {
#define wxFLAGS_MEMBER( v ) { wxT(#v), v },
#define wxEND_FLAGS( e ) \
{ NULL, 0 } }; \
wxEnumData s_enumData##e( s_enumDataMembers##e ); \
wxEnumData *wxGetEnumData(e*) { return &s_enumData##e; } \
template<> void wxStringReadValue(const wxString &s, e &data ) \
{ wxFlagsFromString<e>( s, data ); } \
template<> void wxStringWriteValue( wxString &s, const e& data ) \
{ wxFlagsToString<e>( s, data ); } \
void FromLong##e( long data, wxVariantBase& result ) \
{ result = wxVariantBase(e(data)); } \
void ToLong##e( const wxVariantBase& data, long &result ) \
{ result = (long) data.wxTEMPLATED_MEMBER_CALL(Get, e).m_data; } \
wxTO_STRING_IMP( e ) \
wxFROM_STRING_IMP( e ) \
wxEnumTypeInfo s_typeInfo##e(wxT_SET, &s_enumData##e, \
&wxTO_STRING( e ), &wxFROM_STRING( e ), &ToLong##e, \
&FromLong##e, typeid(e).name() );
// ----------------------------------------------------------------------------
// Type Information
// ----------------------------------------------------------------------------
// All data exposed by the RTTI is characterized using the following classes.
// The first characterization is done by wxTypeKind. All enums up to and including
// wxT_CUSTOM represent so called simple types. These cannot be divided any further.
// They can be converted to and from wxStrings, that's all.
// Other wxTypeKinds can instead be splitted recursively into smaller parts until
// the simple types are reached.
enum wxTypeKind
{
wxT_VOID = 0, // unknown type
wxT_BOOL,
wxT_CHAR,
wxT_UCHAR,
wxT_INT,
wxT_UINT,
wxT_LONG,
wxT_ULONG,
wxT_FLOAT,
wxT_DOUBLE,
wxT_STRING, // must be wxString
wxT_SET, // must be wxBitset<> template
wxT_ENUM,
wxT_CUSTOM, // user defined type (e.g. wxPoint)
wxT_LAST_SIMPLE_TYPE_KIND = wxT_CUSTOM,
wxT_OBJECT_PTR, // object reference
wxT_OBJECT, // embedded object
wxT_COLLECTION, // collection
wxT_DELEGATE, // for connecting against an event source
wxT_LAST_TYPE_KIND = wxT_DELEGATE // sentinel for bad data, asserts, debugging
};
class WXDLLIMPEXP_BASE wxVariantBase;
class WXDLLIMPEXP_BASE wxTypeInfo;
WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxTypeInfo*, wxTypeInfoMap, class WXDLLIMPEXP_BASE );
class WXDLLIMPEXP_BASE wxTypeInfo
{
public:
typedef void (*wxVariant2StringFnc)( const wxVariantBase& data, wxString &result );
typedef void (*wxString2VariantFnc)( const wxString& data, wxVariantBase &result );
wxTypeInfo(wxTypeKind kind,
wxVariant2StringFnc to = NULL, wxString2VariantFnc from = NULL,
const wxString &name = wxEmptyString):
m_toString(to), m_fromString(from), m_kind(kind), m_name(name)
{
Register();
}
#if wxUSE_UNICODE
wxTypeInfo(wxTypeKind kind,
wxVariant2StringFnc to, wxString2VariantFnc from,
const char *name):
m_toString(to), m_fromString(from), m_kind(kind),
m_name(wxString::FromAscii(name))
{
Register();
}
#endif
virtual ~wxTypeInfo()
{
Unregister();
}
// return the kind of this type (wxT_... constants)
wxTypeKind GetKind() const { return m_kind; }
// returns the unique name of this type
const wxString& GetTypeName() const { return m_name; }
// is this type a delegate type
bool IsDelegateType() const { return m_kind == wxT_DELEGATE; }
// is this type a custom type
bool IsCustomType() const { return m_kind == wxT_CUSTOM; }
// is this type an object type
bool IsObjectType() const { return m_kind == wxT_OBJECT || m_kind == wxT_OBJECT_PTR; }
// can the content of this type be converted to and from strings ?
bool HasStringConverters() const { return m_toString != NULL && m_fromString != NULL; }
// convert a wxVariantBase holding data of this type into a string
void ConvertToString( const wxVariantBase& data, wxString &result ) const
{
if ( m_toString )
(*m_toString)( data, result );
else
wxLogError( wxGetTranslation(_T("String conversions not supported")) );
}
// convert a string into a wxVariantBase holding the corresponding data in this type
void ConvertFromString( const wxString& data, wxVariantBase &result ) const
{
if( m_fromString )
(*m_fromString)( data, result );
else
wxLogError( wxGetTranslation(_T("String conversions not supported")) );
}
// statics:
#if wxUSE_UNICODE
static wxTypeInfo *FindType(const char *typeName)
{ return FindType( wxString::FromAscii(typeName) ); }
#endif
static wxTypeInfo *FindType(const wxChar *typeName);
static wxTypeInfo *FindType(const wxString& typeName)
{
#if wxUSE_UNICODE
return FindType( typeName.wchar_str() );
#else
return FindType( typeName.char_str() );
#endif
}
private:
void Register();
void Unregister();
wxVariant2StringFnc m_toString;
wxString2VariantFnc m_fromString;
wxTypeKind m_kind;
wxString m_name;
// the static list of all types we know about
static wxTypeInfoMap* ms_typeTable;
};
class WXDLLIMPEXP_BASE wxBuiltInTypeInfo : public wxTypeInfo
{
public:
wxBuiltInTypeInfo( wxTypeKind kind, wxVariant2StringFnc to = NULL,
wxString2VariantFnc from = NULL,
const wxString &name = wxEmptyString ) :
wxTypeInfo( kind, to, from, name )
{ wxASSERT_MSG( GetKind() < wxT_SET, wxT("Illegal Kind for Base Type") ); }
#if wxUSE_UNICODE
wxBuiltInTypeInfo( wxTypeKind kind, wxVariant2StringFnc to,
wxString2VariantFnc from , const char *name ) :
wxTypeInfo( kind, to, from, name )
{ wxASSERT_MSG( GetKind() < wxT_SET, wxT("Illegal Kind for Base Type") ); }
#endif
};
class WXDLLIMPEXP_BASE wxCustomTypeInfo : public wxTypeInfo
{
public:
wxCustomTypeInfo( const wxString &name, wxVariant2StringFnc to,
wxString2VariantFnc from ) :
wxTypeInfo( wxT_CUSTOM, to, from, name )
{}
#if wxUSE_UNICODE
wxCustomTypeInfo( const char *name , wxVariant2StringFnc to,
wxString2VariantFnc from ) :
wxTypeInfo( wxT_CUSTOM, to, from, name )
{}
#endif
};
class WXDLLIMPEXP_BASE wxEnumTypeInfo : public wxTypeInfo
{
public:
typedef void (*converterToLong_t)( const wxVariantBase& data, long &result );
typedef void (*converterFromLong_t)( long data, wxVariantBase &result );
wxEnumTypeInfo( wxTypeKind kind, wxEnumData* enumInfo, wxVariant2StringFnc to,
wxString2VariantFnc from, converterToLong_t toLong,
converterFromLong_t fromLong, const wxString &name ) :
wxTypeInfo( kind, to, from, name ), m_toLong( toLong ), m_fromLong( fromLong )
{
wxASSERT_MSG( kind == wxT_ENUM || kind == wxT_SET,
wxT("Illegal Kind for Enum Type"));
m_enumInfo = enumInfo;
}
#if wxUSE_UNICODE
wxEnumTypeInfo( wxTypeKind kind, wxEnumData* enumInfo, wxVariant2StringFnc to,
wxString2VariantFnc from, converterToLong_t toLong,
converterFromLong_t fromLong, const char * name ) :
wxTypeInfo( kind, to, from, name ), m_toLong( toLong ), m_fromLong( fromLong )
{
wxASSERT_MSG( kind == wxT_ENUM || kind == wxT_SET,
wxT("Illegal Kind for Enum Type"));
m_enumInfo = enumInfo;
}
#endif
const wxEnumData* GetEnumData() const { return m_enumInfo; }
// convert a wxVariantBase holding data of this type into a long
void ConvertToLong( const wxVariantBase& data, long &result ) const
{
if( m_toLong )
(*m_toLong)( data, result );
else
wxLogError( wxGetTranslation(_T("Long Conversions not supported")) );
}
// convert a long into a wxVariantBase holding the corresponding data in this type
void ConvertFromLong( long data, wxVariantBase &result ) const
{
if( m_fromLong )
(*m_fromLong)( data, result );
else
wxLogError( wxGetTranslation(_T("Long Conversions not supported")) );
}
private:
converterToLong_t m_toLong;
converterFromLong_t m_fromLong;
wxEnumData *m_enumInfo; // Kind == wxT_ENUM or Kind == wxT_SET
};
class WXDLLIMPEXP_BASE wxClassTypeInfo : public wxTypeInfo
{
public:
wxClassTypeInfo( wxTypeKind kind, wxClassInfo* classInfo,
wxVariant2StringFnc to = NULL, wxString2VariantFnc from = NULL,
const wxString &name = wxEmptyString);
#if wxUSE_UNICODE
wxClassTypeInfo( wxTypeKind kind, wxClassInfo* classInfo, wxVariant2StringFnc to,
wxString2VariantFnc from , const char *name );
#endif
const wxClassInfo *GetClassInfo() const { return m_classInfo; }
private:
wxClassInfo *m_classInfo; // Kind == wxT_OBJECT - could be NULL
};
class WXDLLIMPEXP_BASE wxCollectionTypeInfo : public wxTypeInfo
{
public:
wxCollectionTypeInfo( const wxString &elementName, wxVariant2StringFnc to,
wxString2VariantFnc from , const wxString &name) :
wxTypeInfo( wxT_COLLECTION, to, from, name )
{ m_elementTypeName = elementName; m_elementType = NULL; }
#if wxUSE_UNICODE
wxCollectionTypeInfo( const char *elementName, wxVariant2StringFnc to,
wxString2VariantFnc from , const char *name ) :
wxTypeInfo( wxT_COLLECTION, to, from, name )
{ m_elementTypeName = wxString::FromAscii( elementName ); m_elementType = NULL; }
#endif
const wxTypeInfo* GetElementType() const
{
if ( m_elementType == NULL )
m_elementType = wxTypeInfo::FindType( m_elementTypeName );
return m_elementType;
}
private:
mutable wxTypeInfo * m_elementType;
wxString m_elementTypeName;
};
class WXDLLIMPEXP_BASE wxEventSourceTypeInfo : public wxTypeInfo
{
public:
wxEventSourceTypeInfo( int eventType, wxClassInfo* eventClass,
wxVariant2StringFnc to = NULL,
wxString2VariantFnc from = NULL );
wxEventSourceTypeInfo( int eventType, int lastEventType, wxClassInfo* eventClass,
wxVariant2StringFnc to = NULL, wxString2VariantFnc from = NULL );
int GetEventType() const { return m_eventType; }
int GetLastEventType() const { return m_lastEventType; }
const wxClassInfo* GetEventClass() const { return m_eventClass; }
private:
const wxClassInfo *m_eventClass; // (extended will merge into classinfo)
int m_eventType;
int m_lastEventType;
};
template<typename T> const wxTypeInfo* wxGetTypeInfo( T * ) \
{ return wxTypeInfo::FindType(typeid(T).name()); }
// this macro is for usage with custom, non-object derived classes and structs,
// wxPoint is such a custom type
#if wxUSE_FUNC_TEMPLATE_POINTER
#define wxCUSTOM_TYPE_INFO( e, toString, fromString ) \
wxCustomTypeInfo s_typeInfo##e(typeid(e).name(), &toString, &fromString);
#else
#define wxCUSTOM_TYPE_INFO( e, toString, fromString ) \
void ToString##e( const wxVariantBase& data, wxString &result ) \
{ toString(data, result); } \
void FromString##e( const wxString& data, wxVariantBase &result ) \
{ fromString(data, result); } \
wxCustomTypeInfo s_typeInfo##e(typeid(e).name(), \
&ToString##e, &FromString##e);
#endif
#define wxCOLLECTION_TYPE_INFO( element, collection ) \
wxCollectionTypeInfo s_typeInfo##collection( typeid(element).name(), \
NULL, NULL, typeid(collection).name() );
// sometimes a compiler invents specializations that are nowhere called,
// use this macro to satisfy the refs, currently we don't have to play
// tricks, but if we will have to according to the compiler, we will use
// that macro for that
#define wxILLEGAL_TYPE_SPECIALIZATION( a )
#endif // wxUSE_EXTENDED_RTTI
#endif // _XTITYPES_H_