+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 ( int 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.IsEmpty() )
+ s +="|" ;
+ s += edata->GetEnumMemberNameByIndex(i) ;
+ }
+ }
+}
+
+#define WX_BEGIN_FLAGS( e ) \
+ wxEnumMemberData s_enumDataMembers##e[] = {
+
+#define WX_FLAGS_MEMBER( v ) { #v, v } ,
+
+#define WX_END_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 , wxxVariant& result ) { result = wxxVariant(e(data)) ;} \
+ void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.Get<e>().m_data ;} \
+template<> const wxTypeInfo* wxGetTypeInfo( e * ) \
+{ \
+ static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e , &wxToStringConverter<e> , &wxFromStringConverter<e> , &ToLong##e , &FromLong##e, #e ) ; return &s_typeInfo ; \
+}