X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9b5bafcf38a1c6b1ad9f8974e4745c73a559a26e..d7c37bdf337d7ca687263520de432eee4a3722db:/samples/propgrid/sampleprops.cpp diff --git a/samples/propgrid/sampleprops.cpp b/samples/propgrid/sampleprops.cpp index 21303e7af4..20778a9673 100644 --- a/samples/propgrid/sampleprops.cpp +++ b/samples/propgrid/sampleprops.cpp @@ -4,9 +4,8 @@ // Author: Jaakko Salli // Modified by: // Created: 2006-03-05 -// RCS-ID: $Id$ // Copyright: (c) Jaakko Salli -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx/wx.h". @@ -22,6 +21,8 @@ #include "wx/wx.h" #endif +#include "wx/fontdlg.h" + // ----------------------------------------------------------------------- @@ -46,8 +47,6 @@ bool operator == (const wxFontData&, const wxFontData&) // Custom version of wxFontProperty that also holds colour in the value. // Original version by Vladimir Vainer. -#include - IMPLEMENT_VARIANT_OBJECT_SHALLOWCMP(wxFontData) WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontDataProperty,wxFontProperty, @@ -60,7 +59,7 @@ wxFontDataProperty::wxFontDataProperty( const wxString& label, const wxString& n // Fix value. fontData.SetChosenFont(value.GetInitialFont()); - if ( !fontData.GetColour().Ok() ) + if ( !fontData.GetColour().IsOk() ) fontData.SetColour(*wxBLACK); // Set initial value - should be done in a simpler way like this @@ -68,8 +67,8 @@ wxFontDataProperty::wxFontDataProperty( const wxString& label, const wxString& n m_value_wxFontData << value; // Add extra children. - AddChild( new wxColourProperty(_("Colour"), wxPG_LABEL, - fontData.GetColour() ) ); + AddPrivateChild( new wxColourProperty(_("Colour"), wxPG_LABEL, + fontData.GetColour() ) ); } wxFontDataProperty::~wxFontDataProperty () { } @@ -113,7 +112,7 @@ void wxFontDataProperty::OnSetValue() fontData << m_value_wxFontData; wxFont font = fontData.GetChosenFont(); - if ( !font.Ok() ) + if ( !font.IsOk() ) font = wxFont(10,wxSWISS,wxNORMAL,wxNORMAL); m_value = WXVARIANT(font); @@ -131,7 +130,7 @@ bool wxFontDataProperty::OnEvent( wxPropertyGrid* propgrid, { if ( propgrid->IsMainButtonEvent(event) ) { - wxVariant useValue = propgrid->GetPendingEditedValue(); + wxVariant useValue = propgrid->GetUncommittedPropertyValue(); wxFontData fontData; fontData << useValue; @@ -161,7 +160,9 @@ void wxFontDataProperty::RefreshChildren() Item(6)->SetValue( variant ); } -void wxFontDataProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxFontDataProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { wxFontData fontData; fontData << thisValue; @@ -183,7 +184,9 @@ void wxFontDataProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxV fontData.SetChosenFont(font); } - thisValue << fontData; + wxVariant newVariant; + newVariant << fontData; + return newVariant; } // ----------------------------------------------------------------------- @@ -197,8 +200,8 @@ wxSizeProperty::wxSizeProperty( const wxString& label, const wxString& name, const wxSize& value) : wxPGProperty(label,name) { SetValueI(value); - AddChild( new wxIntProperty(wxT("Width"),wxPG_LABEL,value.x) ); - AddChild( new wxIntProperty(wxT("Height"),wxPG_LABEL,value.y) ); + AddPrivateChild( new wxIntProperty(wxT("Width"),wxPG_LABEL,value.x) ); + AddPrivateChild( new wxIntProperty(wxT("Height"),wxPG_LABEL,value.y) ); } wxSizeProperty::~wxSizeProperty() { } @@ -211,15 +214,20 @@ void wxSizeProperty::RefreshChildren() Item(1)->SetValue( (long)size.y ); } -void wxSizeProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxSizeProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { wxSize& size = wxSizeRefFromVariant(thisValue); - int val = wxPGVariantToInt(childValue); + int val = childValue.GetLong(); switch ( childIndex ) { case 0: size.x = val; break; case 1: size.y = val; break; } + wxVariant newVariant; + newVariant << size; + return newVariant; } // ----------------------------------------------------------------------- @@ -233,8 +241,8 @@ wxPointProperty::wxPointProperty( const wxString& label, const wxString& name, const wxPoint& value) : wxPGProperty(label,name) { SetValueI(value); - AddChild( new wxIntProperty(wxT("X"),wxPG_LABEL,value.x) ); - AddChild( new wxIntProperty(wxT("Y"),wxPG_LABEL,value.y) ); + AddPrivateChild( new wxIntProperty(wxT("X"),wxPG_LABEL,value.x) ); + AddPrivateChild( new wxIntProperty(wxT("Y"),wxPG_LABEL,value.y) ); } wxPointProperty::~wxPointProperty() { } @@ -247,15 +255,20 @@ void wxPointProperty::RefreshChildren() Item(1)->SetValue( (long)point.y ); } -void wxPointProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxPointProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { wxPoint& point = wxPointRefFromVariant(thisValue); - int val = wxPGVariantToInt(childValue); + int val = childValue.GetLong(); switch ( childIndex ) { case 0: point.x = val; break; case 1: point.y = val; break; } + wxVariant newVariant; + newVariant << point; + return newVariant; } @@ -263,7 +276,8 @@ void wxPointProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVari // Dirs Property // ----------------------------------------------------------------------- -WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(wxDirsProperty,wxT(','),wxT("Browse")) +WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(wxDirsProperty, ',', + "Browse") #if wxUSE_VALIDATORS @@ -300,7 +314,7 @@ bool wxDirsProperty::OnCustomStringEdit( wxWindow* parent, wxString& value ) // by replacing each ArrayDouble with ArrayXXX. // -class wxArrayDoubleEditorDialog : public wxArrayEditorDialog +class wxArrayDoubleEditorDialog : public wxPGArrayEditorDialog { public: wxArrayDoubleEditorDialog(); @@ -354,7 +368,7 @@ private: DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayDoubleEditorDialog) }; -IMPLEMENT_DYNAMIC_CLASS(wxArrayDoubleEditorDialog, wxArrayEditorDialog) +IMPLEMENT_DYNAMIC_CLASS(wxArrayDoubleEditorDialog, wxPGArrayEditorDialog) // // Array dialog array access and manipulation @@ -412,14 +426,14 @@ void wxArrayDoubleEditorDialog::ArraySwap( size_t first, size_t second ) // wxArrayDoubleEditorDialog::wxArrayDoubleEditorDialog() - : wxArrayEditorDialog() + : wxPGArrayEditorDialog() { Init(); } void wxArrayDoubleEditorDialog::Init() { - wxArrayEditorDialog::Init(); + wxPGArrayEditorDialog::Init(); SetPrecision(-1); } @@ -430,7 +444,7 @@ wxArrayDoubleEditorDialog::wxArrayDoubleEditorDialog(wxWindow *parent, long style, const wxPoint& pos, const wxSize& sz ) - : wxArrayEditorDialog() + : wxPGArrayEditorDialog() { Init(); Create(parent,message,caption,array,style,pos,sz); @@ -447,7 +461,7 @@ bool wxArrayDoubleEditorDialog::Create(wxWindow *parent, m_array = array; - return wxArrayEditorDialog::Create (parent,message,caption,style,pos,sz); + return wxPGArrayEditorDialog::Create (parent,message,caption,style,pos,sz); } // ----------------------------------------------------------------------- @@ -509,16 +523,29 @@ wxArrayDoubleProperty::~wxArrayDoubleProperty () { } void wxArrayDoubleProperty::OnSetValue() { + // Generate cached display string, to optimize grid drawing GenerateValueAsString( m_display, m_precision, true ); } -wxString wxArrayDoubleProperty::GetValueAsString( int arg_flags ) const +wxString wxArrayDoubleProperty::ValueToString( wxVariant& value, + int argFlags ) const { - if ( !(arg_flags & wxPG_FULL_VALUE )) - return m_display; - wxString s; - GenerateValueAsString(s,-1,false); + + if ( argFlags & wxPG_FULL_VALUE ) + { + GenerateValueAsString(s,-1,false); + } + else + { + // + // Display cached string only if value truly matches m_value + if ( value.GetData() == m_value.GetData() ) + return m_display; + else + GenerateValueAsString( s, m_precision, true ); + } + return s; } @@ -554,7 +581,7 @@ bool wxArrayDoubleProperty::OnEvent( wxPropertyGrid* propgrid, if ( propgrid->IsMainButtonEvent(event) ) { // Update the value in case of last minute changes - wxVariant useValue = propgrid->GetPendingEditedValue(); + wxVariant useValue = propgrid->GetUncommittedPropertyValue(); wxArrayDouble& value = wxArrayDoubleRefFromVariant(useValue); @@ -590,7 +617,7 @@ bool wxArrayDoubleProperty::StringToValue( wxVariant& variant, const wxString& t WX_PG_TOKENIZER1_BEGIN(text,delimiter) - if ( token.length() ) + if ( !token.empty() ) { // If token was invalid, exit the loop now