Have support for both char* and wchar_t* in wxPGPropArg. Moved wxPGPropArgCls member function to propgridiface.cpp which is more logical location since class is in propgridiface.h. Added char* test cases.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55607 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
8f18b25245
commit
f379342915
@ -31,61 +31,81 @@ public:
|
||||
wxPGPropArgCls( const wxPGProperty* property )
|
||||
{
|
||||
m_ptr.property = (wxPGProperty*) property;
|
||||
m_isName = false;
|
||||
m_flags = IsProperty;
|
||||
}
|
||||
wxPGPropArgCls( const wxString& str )
|
||||
{
|
||||
m_ptr.name = &str;
|
||||
m_isName = 1;
|
||||
m_ptr.stringName = &str;
|
||||
m_flags = IsWxString;
|
||||
}
|
||||
wxPGPropArgCls( const wxPGPropArgCls& id )
|
||||
{
|
||||
m_ptr = id.m_ptr;
|
||||
m_isName = id.m_isName;
|
||||
m_flags = id.m_flags;
|
||||
}
|
||||
// This is only needed for wxPython bindings
|
||||
wxPGPropArgCls( wxString* str, bool WXUNUSED(deallocPtr) )
|
||||
{
|
||||
m_ptr.name = str;
|
||||
m_isName = 3; // Like 1, but causes ptr to be deallocated in dtor
|
||||
m_ptr.stringName = str;
|
||||
m_flags = IsWxString | OwnsWxString;
|
||||
}
|
||||
~wxPGPropArgCls()
|
||||
{
|
||||
if ( m_isName == 3 )
|
||||
delete m_ptr.name;
|
||||
if ( m_flags & OwnsWxString )
|
||||
delete m_ptr.stringName;
|
||||
}
|
||||
wxPGProperty* GetPtr() const
|
||||
{
|
||||
wxCHECK( !m_isName, NULL );
|
||||
wxCHECK( m_flags == IsProperty, NULL );
|
||||
return m_ptr.property;
|
||||
}
|
||||
wxPGPropArgCls( const wxChar* str )
|
||||
wxPGPropArgCls( const char* str )
|
||||
{
|
||||
m_ptr.rawname = str;
|
||||
m_isName = 2;
|
||||
m_ptr.charName = str;
|
||||
m_flags = IsCharPtr;
|
||||
}
|
||||
#if wxUSE_WCHAR_T
|
||||
wxPGPropArgCls( const wchar_t* str )
|
||||
{
|
||||
m_ptr.wcharName = str;
|
||||
m_flags = IsWCharPtr;
|
||||
}
|
||||
#endif
|
||||
/** This constructor is required for NULL. */
|
||||
wxPGPropArgCls( int )
|
||||
{
|
||||
m_ptr.property = (wxPGProperty*) NULL;
|
||||
m_isName = false;
|
||||
m_flags = IsProperty;
|
||||
}
|
||||
wxPGProperty* GetPtr( wxPropertyGridInterface* methods ) const;
|
||||
wxPGProperty* GetPtr( const wxPropertyGridInterface* methods ) const
|
||||
wxPGProperty* GetPtr( wxPropertyGridInterface* iface ) const;
|
||||
wxPGProperty* GetPtr( const wxPropertyGridInterface* iface ) const
|
||||
{
|
||||
return GetPtr((wxPropertyGridInterface*)methods);
|
||||
return GetPtr((wxPropertyGridInterface*)iface);
|
||||
}
|
||||
wxPGProperty* GetPtr0() const { return m_ptr.property; }
|
||||
unsigned char HasName() const { return m_isName; }
|
||||
const wxString& GetName() const { return *m_ptr.name; }
|
||||
bool HasName() const { return (m_flags != IsProperty); }
|
||||
const wxString& GetName() const { return *m_ptr.stringName; }
|
||||
private:
|
||||
|
||||
enum
|
||||
{
|
||||
IsProperty = 0x00,
|
||||
IsWxString = 0x01,
|
||||
IsCharPtr = 0x02,
|
||||
IsWCharPtr = 0x04,
|
||||
OwnsWxString = 0x10,
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
wxPGProperty* property;
|
||||
const wxChar* rawname;
|
||||
const wxString* name;
|
||||
const char* charName;
|
||||
#if wxUSE_WCHAR_T
|
||||
const wchar_t* wcharName;
|
||||
#endif
|
||||
const wxString* stringName;
|
||||
} m_ptr;
|
||||
unsigned char m_isName;
|
||||
unsigned char m_flags;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -739,6 +739,10 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
{
|
||||
RT_START_TEST(SetPropertyValue_and_GetPropertyValue)
|
||||
|
||||
// In this section, mixed up usage of wxT("propname") and "propname"
|
||||
// in wxPropertyGridInterface functions is intentional.
|
||||
// Purpose is to test wxPGPropArgCls ctors.
|
||||
|
||||
//pg = (wxPropertyGrid*) NULL;
|
||||
|
||||
wxArrayString test_arrstr_1;
|
||||
@ -879,25 +883,26 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
// Make sure children of composite parent get updated as well
|
||||
// Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000"
|
||||
|
||||
//
|
||||
// This updates children as well
|
||||
wxString nvs = "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002";
|
||||
pgman->SetPropertyValue(wxT("Car"), nvs);
|
||||
pgman->SetPropertyValue("Car", nvs);
|
||||
|
||||
if ( pgman->GetPropertyValueAsString(wxT("Car.Model")) != "Lamborghini Diablo XYZ" )
|
||||
if ( pgman->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
|
||||
{
|
||||
wxLogDebug("Did not match: Car.Model=%s", pgman->GetPropertyValueAsString(wxT("Car.Model")).c_str());
|
||||
wxLogDebug("Did not match: Car.Model=%s", pgman->GetPropertyValueAsString("Car.Model").c_str());
|
||||
RT_FAILURE();
|
||||
}
|
||||
|
||||
if ( pgman->GetPropertyValueAsInt(wxT("Car.Speeds.Max. Speed (mph)")) != 100 )
|
||||
if ( pgman->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
|
||||
{
|
||||
wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman->GetPropertyValueAsString(wxT("Car.Speeds.Max. Speed (mph)")).c_str());
|
||||
wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
|
||||
RT_FAILURE();
|
||||
}
|
||||
|
||||
if ( pgman->GetPropertyValueAsInt(wxT("Car.Price ($)")) != 3000002 )
|
||||
if ( pgman->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
|
||||
{
|
||||
wxLogDebug("Did not match: Car.Price ($)=%s", pgman->GetPropertyValueAsString(wxT("Car.Price ($)")).c_str());
|
||||
wxLogDebug("Did not match: Car.Price ($)=%s", pgman->GetPropertyValueAsString("Car.Price ($)").c_str());
|
||||
RT_FAILURE();
|
||||
}
|
||||
}
|
||||
|
@ -1603,26 +1603,6 @@ int wxPGProperty::GetY() const
|
||||
return GetY2(GetGrid()->GetRowHeight());
|
||||
}
|
||||
|
||||
|
||||
wxPGProperty* wxPGPropArgCls::GetPtr( wxPropertyGridInterface* methods ) const
|
||||
{
|
||||
if ( !m_isName )
|
||||
{
|
||||
wxASSERT_MSG( m_ptr.property, wxT("invalid property ptr") );
|
||||
return m_ptr.property;
|
||||
}
|
||||
else if ( m_isName == 1 )
|
||||
return methods->GetPropertyByNameA(*m_ptr.name);
|
||||
else if ( m_isName == 2 )
|
||||
return methods->GetPropertyByNameA(m_ptr.rawname);
|
||||
// 3 is like 1, but ptr is freed in dtor - only needed by wxPython bindings.
|
||||
else if ( m_isName == 3 )
|
||||
return methods->GetPropertyByNameA(*m_ptr.name);
|
||||
|
||||
wxASSERT( m_isName <= 3 );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This is used by Insert etc.
|
||||
void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
|
||||
{
|
||||
|
@ -200,6 +200,29 @@ bool wxPGVariantToDouble( const wxVariant& variant, double* pResult )
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// wxPGPropArgCls
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
wxPGProperty* wxPGPropArgCls::GetPtr( wxPropertyGridInterface* iface ) const
|
||||
{
|
||||
if ( m_flags == IsProperty )
|
||||
{
|
||||
wxASSERT_MSG( m_ptr.property, wxT("invalid property ptr") );
|
||||
return m_ptr.property;
|
||||
}
|
||||
else if ( m_flags & IsWxString )
|
||||
return iface->GetPropertyByNameA(*m_ptr.stringName);
|
||||
else if ( m_flags & IsCharPtr )
|
||||
return iface->GetPropertyByNameA(m_ptr.charName);
|
||||
#if wxUSE_WCHAR_T
|
||||
else if ( m_flags & IsWCharPtr )
|
||||
return iface->GetPropertyByNameA(m_ptr.wcharName);
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Choice related methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user