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
{
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;
// 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();
}
}
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 )
{
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
// -----------------------------------------------------------------------