XTI extensions

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23023 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2003-08-19 16:40:20 +00:00
parent 9409aa35b8
commit b8d5be011d
3 changed files with 143 additions and 124 deletions

View File

@@ -58,6 +58,15 @@ wxString wxItemContainer::GetStringSelection() const
return s; return s;
} }
wxArrayString wxItemContainer::GetStrings() const
{
wxArrayString result ;
size_t count = GetCount() ;
for ( size_t n = 0 ; n < count ; n++ )
result.Add(GetString(n));
return result ;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// appending items // appending items
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -28,7 +28,8 @@
#include "wx/xml/xml.h" #include "wx/xml/xml.h"
#include "wx/tokenzr.h" #include "wx/tokenzr.h"
#include "wx/notebook.h"
#include "wx/list.h"
#include <string.h> #include <string.h>
#if wxUSE_EXTENDED_RTTI #if wxUSE_EXTENDED_RTTI
@@ -104,89 +105,6 @@ const char * wxEnumData::GetEnumMemberNameByIndex( int idx )
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Type Information // Type Information
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
template<> const wxTypeInfo* wxGetTypeInfo( void * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( bool * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_BOOL ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( char * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( unsigned char * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( int * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( unsigned int * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( long * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( unsigned long * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( float * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_FLOAT ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( double * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_DOUBLE ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( wxString * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_STRING ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( wxWindowList * )
{
static wxCollectionTypeInfo s_typeInfo( (wxTypeInfo*) wxGetTypeInfo( (wxWindow **) NULL) ) ;
return &s_typeInfo ;
}
// this are compiler induced specialization which are never used anywhere
WX_ILLEGAL_TYPE_SPECIALIZATION( char const * )
WX_ILLEGAL_TYPE_SPECIALIZATION( char * )
WX_ILLEGAL_TYPE_SPECIALIZATION( unsigned char * )
WX_ILLEGAL_TYPE_SPECIALIZATION( int * )
WX_ILLEGAL_TYPE_SPECIALIZATION( bool * )
WX_ILLEGAL_TYPE_SPECIALIZATION( long * )
WX_ILLEGAL_TYPE_SPECIALIZATION( wxString * )
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// value streaming // value streaming
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -372,6 +290,100 @@ template<> void wxStringWriteValue(wxString & , wxSize * const & )
WX_CUSTOM_TYPE_INFO(wxSize) WX_CUSTOM_TYPE_INFO(wxSize)
template<> const wxTypeInfo* wxGetTypeInfo( void * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( bool * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_BOOL , &wxToStringConverter<bool> , &wxFromStringConverter<bool>) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( char * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR , &wxToStringConverter<char> , &wxFromStringConverter<char>) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( unsigned char * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR , &wxToStringConverter< unsigned char > , &wxFromStringConverter<unsigned char>) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( int * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR , &wxToStringConverter<int> , &wxFromStringConverter<int>) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( unsigned int * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR , &wxToStringConverter<unsigned int> , &wxFromStringConverter<unsigned int>) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( long * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_LONG , &wxToStringConverter<long> , &wxFromStringConverter<long>) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( unsigned long * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_ULONG , &wxToStringConverter<unsigned long> , &wxFromStringConverter<unsigned long>) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( float * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_FLOAT , &wxToStringConverter<float> , &wxFromStringConverter<float>) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( double * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_DOUBLE , &wxToStringConverter<double> , &wxFromStringConverter<double>) ;
return &s_typeInfo ;
}
template<> const wxTypeInfo* wxGetTypeInfo( wxString * )
{
static wxBuiltInTypeInfo s_typeInfo( wxT_STRING , &wxToStringConverter<wxString> , &wxFromStringConverter<wxString>) ;
return &s_typeInfo ;
}
// this are compiler induced specialization which are never used anywhere
WX_ILLEGAL_TYPE_SPECIALIZATION( char const * )
WX_ILLEGAL_TYPE_SPECIALIZATION( char * )
WX_ILLEGAL_TYPE_SPECIALIZATION( unsigned char * )
WX_ILLEGAL_TYPE_SPECIALIZATION( int * )
WX_ILLEGAL_TYPE_SPECIALIZATION( bool * )
WX_ILLEGAL_TYPE_SPECIALIZATION( long * )
WX_ILLEGAL_TYPE_SPECIALIZATION( wxString * )
//
// make wxWindowList known
template<> const wxTypeInfo* wxGetTypeInfo( wxArrayString * )
{
static wxCollectionTypeInfo s_typeInfo( (wxTypeInfo*) wxGetTypeInfo( (wxString *) NULL) ) ;
return &s_typeInfo ;
}
template<> void wxCollectionToVariantArray( wxArrayString const &theArray, wxxVariantArray &value)
{
wxArrayCollectionToVariantArray( theArray , value ) ;
}
/* /*
template<> void wxStringReadValue(const wxString &s , wxColour &data ) template<> void wxStringReadValue(const wxString &s , wxColour &data )
@@ -507,19 +519,23 @@ wxxVariant wxClassInfo::GetProperty(wxObject *object, const char *propertyName)
accessor = FindAccessor(propertyName); accessor = FindAccessor(propertyName);
wxASSERT(accessor->HasGetter()); wxASSERT(accessor->HasGetter());
return accessor->GetProperty(object); wxxVariant result ;
accessor->GetProperty(object,result);
return result ;
} }
wxxVariantArray wxClassInfo::GetPropertyCollection(wxObject *object, const wxChar *propertyName) const wxxVariantArray wxClassInfo::GetPropertyCollection(wxObject *object, const wxChar *propertyName) const
{ {
const wxPropertyAccessor *accessor; const wxPropertyAccessor *accessor;
accessor = FindAccessor(propertyName); accessor = FindAccessor(propertyName);
wxASSERT(accessor->HasGetter()); wxASSERT(accessor->HasGetter());
return accessor->GetPropertyCollection(object); wxxVariantArray result ;
accessor->GetPropertyCollection(object,result);
return result ;
} }
void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const
{ {
const wxPropertyAccessor *accessor; const wxPropertyAccessor *accessor;
@@ -555,7 +571,7 @@ struct wxDynamicObject::wxDynamicObjectInternal
} ; } ;
// instantiates this object with an instance of its superclass // instantiates this object with an instance of its superclass
wxDynamicObject::wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) wxDynamicObject::wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info)
{ {
m_superClassInstance = superClassInstance ; m_superClassInstance = superClassInstance ;
m_classInfo = info ; m_classInfo = info ;
@@ -585,7 +601,7 @@ wxxVariant wxDynamicObject::GetProperty (const wxChar *propertyName) const
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxDynamicClassInfo::wxDynamicClassInfo( const wxChar *unitName, const wxChar *className , const wxClassInfo* superClass ) : wxDynamicClassInfo::wxDynamicClassInfo( const wxChar *unitName, const wxChar *className , const wxClassInfo* superClass ) :
wxClassInfo( unitName, className , new const wxClassInfo*[2]) wxClassInfo( unitName, className , new const wxClassInfo*[2])
{ {
GetParents()[0] = superClass ; GetParents()[0] = superClass ;
GetParents()[1] = NULL ; GetParents()[1] = NULL ;
@@ -596,13 +612,13 @@ wxDynamicClassInfo::~wxDynamicClassInfo()
delete[] GetParents() ; delete[] GetParents() ;
} }
wxObject *wxDynamicClassInfo::AllocateObject() const wxObject *wxDynamicClassInfo::AllocateObject() const
{ {
wxObject* parent = GetParents()[0]->AllocateObject() ; wxObject* parent = GetParents()[0]->AllocateObject() ;
return new wxDynamicObject( parent , this ) ; return new wxDynamicObject( parent , this ) ;
} }
void wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxxVariant *params) const void wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxxVariant *params) const
{ {
wxDynamicObject *dynobj = dynamic_cast< wxDynamicObject *>( object ) ; wxDynamicObject *dynobj = dynamic_cast< wxDynamicObject *>( object ) ;
wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::Create on an object other than wxDynamicObject") ) ; wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::Create on an object other than wxDynamicObject") ) ;
@@ -610,13 +626,13 @@ void wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxxVariant *p
} }
// get number of parameters for constructor // get number of parameters for constructor
int wxDynamicClassInfo::GetCreateParamCount() const int wxDynamicClassInfo::GetCreateParamCount() const
{ {
return GetParents()[0]->GetCreateParamCount() ; return GetParents()[0]->GetCreateParamCount() ;
} }
// get i-th constructor parameter // get i-th constructor parameter
const wxChar* wxDynamicClassInfo::GetCreateParamName(int i) const const wxChar* wxDynamicClassInfo::GetCreateParamName(int i) const
{ {
return GetParents()[0]->GetCreateParamName( i ) ; return GetParents()[0]->GetCreateParamName( i ) ;
} }
@@ -641,12 +657,12 @@ wxxVariant wxDynamicClassInfo::GetProperty(wxObject *object, const char *propert
return GetParents()[0]->GetProperty( dynobj->GetSuperClassInstance() , propertyName ) ; return GetParents()[0]->GetProperty( dynobj->GetSuperClassInstance() , propertyName ) ;
} }
void wxDynamicClassInfo::AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) void wxDynamicClassInfo::AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo )
{ {
new wxPropertyInfo( m_firstProperty , propertyName , typeInfo , new wxGenericPropertyAccessor( propertyName ) , wxxVariant() ) ; new wxPropertyInfo( m_firstProperty , propertyName , typeInfo , new wxGenericPropertyAccessor( propertyName ) , wxxVariant() ) ;
} }
void wxDynamicClassInfo::AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) void wxDynamicClassInfo::AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo )
{ {
new wxHandlerInfo( m_firstHandler , handlerName , address , eventClassInfo ) ; new wxHandlerInfo( m_firstHandler , handlerName , address , eventClassInfo ) ;
} }
@@ -657,44 +673,33 @@ void wxDynamicClassInfo::AddHandler( const wxChar *handlerName , wxObjectEventFu
struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal
{ {
wxString m_propertyName ; char filler ;
} ; } ;
wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxChar* propertyName ) wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxString& propertyName )
: wxPropertyAccessor( NULL , NULL , NULL , NULL )
{ {
m_data = new wxGenericPropertyAccessorInternal ; m_data = new wxGenericPropertyAccessorInternal ;
m_data->m_propertyName = propertyName ; m_propertyName = propertyName ;
m_getterName = wxT("Get")+propertyName ;
m_setterName = wxT("Set")+propertyName ;
} }
wxGenericPropertyAccessor::~wxGenericPropertyAccessor() wxGenericPropertyAccessor::~wxGenericPropertyAccessor()
{ {
delete m_data ; delete m_data ;
} }
void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxxVariant &value) const void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxxVariant &value) const
{ {
wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ; wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
dynobj->SetProperty(m_data->m_propertyName , value ) ; dynobj->SetProperty(m_propertyName , value ) ;
} }
wxxVariant wxGenericPropertyAccessor::GetProperty(const wxObject *object) const void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxxVariant& value) const
{ {
const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject * >( object ) ; const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject * >( object ) ;
wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
return dynobj->GetProperty( m_data->m_propertyName ) ; value = dynobj->GetProperty( m_propertyName ) ;
} }
wxxVariant wxGenericPropertyAccessor::ReadValue( const wxString &value ) const
{
return wxxVariant(value) ;
}
void wxGenericPropertyAccessor::WriteValue( wxString& value , const wxObject *object ) const
{
const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject * >( object ) ;
wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
wxxVariant val = dynobj->GetProperty( m_data->m_propertyName ) ;
value = val.GetAsString() ;
}
#endif #endif

View File

@@ -170,7 +170,8 @@ void wxWriter::WriteAllProperties( const wxObject * obj , const wxClassInfo* ci
DoBeginWriteProperty( pi ) ; DoBeginWriteProperty( pi ) ;
if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION ) if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION )
{ {
wxxVariantArray data = pi->GetAccessor()->GetPropertyCollection(obj) ; wxxVariantArray data ;
pi->GetAccessor()->GetPropertyCollection(obj, data) ;
const wxTypeInfo * elementType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() )->GetElementType() ; const wxTypeInfo * elementType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() )->GetElementType() ;
for ( size_t i = 0 ; i < data.GetCount() ; ++i ) for ( size_t i = 0 ; i < data.GetCount() ; ++i )
{ {
@@ -216,7 +217,8 @@ void wxWriter::WriteAllProperties( const wxObject * obj , const wxClassInfo* ci
} }
else else
{ {
wxxVariant value = pi->GetAccessor()->GetProperty(obj) ; wxxVariant value ;
pi->GetAccessor()->GetProperty(obj, value) ;
if ( persister->BeforeWriteProperty( this , pi , value ) ) if ( persister->BeforeWriteProperty( this , pi , value ) )
{ {
const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( pi->GetTypeInfo() ) ; const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( pi->GetTypeInfo() ) ;
@@ -534,7 +536,7 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
else else
{ {
createParamOids[i] = wxInvalidObjectID ; createParamOids[i] = wxInvalidObjectID ;
createParams[i] = ReadValue( prop , pi->GetAccessor() ) ; createParams[i] = ReadValue( prop , pi->GetTypeInfo() ) ;
createClassInfos[i] = NULL ; createClassInfos[i] = NULL ;
} }
@@ -591,7 +593,7 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
} }
else else
{ {
wxxVariant elementValue = ReadValue( prop , pi->GetAccessor() ) ; wxxVariant elementValue = ReadValue( elementContent , elementType ) ;
if ( pi->GetAccessor()->HasAdder() ) if ( pi->GetAccessor()->HasAdder() )
callbacks->AddToPropertyCollection( objectID , classInfo ,pi , elementValue ) ; callbacks->AddToPropertyCollection( objectID , classInfo ,pi , elementValue ) ;
} }
@@ -626,7 +628,8 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
} }
else else
{ {
callbacks->SetProperty( objectID, classInfo ,pi , ReadValue( prop , pi->GetAccessor() ) ) ; wxxVariant nodeval ;
callbacks->SetProperty( objectID, classInfo ,pi , ReadValue( prop , pi->GetTypeInfo() ) ) ;
} }
} }
} }
@@ -640,12 +643,14 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
} }
wxxVariant wxXmlReader::ReadValue(wxXmlNode *node, wxxVariant wxXmlReader::ReadValue(wxXmlNode *node,
wxPropertyAccessor *accessor ) const wxTypeInfo *type )
{ {
wxString content ; wxString content ;
if ( node ) if ( node )
content = node->GetContent() ; content = node->GetContent() ;
return accessor->ReadValue(content) ; wxxVariant result ;
type->ConvertFromString( content , result ) ;
return result ;
} }
int wxXmlReader::ReadObject( const wxString &name , wxDepersister *callbacks) int wxXmlReader::ReadObject( const wxString &name , wxDepersister *callbacks)