]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/propgrid/sampleprops.cpp
Correct wxImage::Size() again; add unit tests for it.
[wxWidgets.git] / samples / propgrid / sampleprops.cpp
index 459de82c475908e813dd94aaeaaaf40221e1fe0d..18b608fbc534a43f604614e902cabe2755ef9af3 100644 (file)
@@ -68,8 +68,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 () { }
@@ -131,11 +131,10 @@ bool wxFontDataProperty::OnEvent( wxPropertyGrid* propgrid,
 {
     if ( propgrid->IsMainButtonEvent(event) )
     {
-        // Update value from last minute changes
-        PrepareValueForDialogEditing(propgrid);
+        wxVariant useValue = propgrid->GetUncommittedPropertyValue();
 
         wxFontData fontData;
-        fontData << m_value_wxFontData;
+        fontData << useValue;
 
         fontData.SetInitialFont(fontData.GetChosenFont());
 
@@ -162,7 +161,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;
@@ -184,7 +185,9 @@ void wxFontDataProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxV
             fontData.SetChosenFont(font);
     }
 
-    thisValue << fontData;
+    wxVariant newVariant;
+    newVariant << fontData;
+    return newVariant;
 }
 
 // -----------------------------------------------------------------------
@@ -198,8 +201,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() { }
@@ -212,15 +215,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;
 }
 
 // -----------------------------------------------------------------------
@@ -234,8 +242,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() { }
@@ -248,15 +256,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;
 }
 
 
@@ -510,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,10 +580,10 @@ bool wxArrayDoubleProperty::OnEvent( wxPropertyGrid* propgrid,
 {
     if ( propgrid->IsMainButtonEvent(event) )
     {
-        wxArrayDouble& value = wxArrayDoubleRefFromVariant(m_value);
-
         // Update the value in case of last minute changes
-        PrepareValueForDialogEditing(propgrid);
+        wxVariant useValue = propgrid->GetUncommittedPropertyValue();
+
+        wxArrayDouble& value = wxArrayDoubleRefFromVariant(useValue);
 
         // Create editor dialog.
         wxArrayDoubleEditorDialog dlg;