]> git.saurik.com Git - wxWidgets.git/blobdiff - src/propgrid/property.cpp
Set event object correctly for the generated wxSizeEvents.
[wxWidgets.git] / src / propgrid / property.cpp
index e759aa5d7288e5373eb80296d1c0543da8d598e4..f878d4ddda066e5c3895b3e8afd8a518e3734bdd 100644 (file)
@@ -35,6 +35,8 @@
     #include "wx/intl.h"
 #endif
 
+#include "wx/image.h"
+
 #include "wx/propgrid/propgrid.h"
 
 
@@ -206,7 +208,7 @@ bool wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
             {
                 text = propertyGrid->GetCommonValueLabel(cmnVal);
                 DrawText( dc, rect, 0, text );
-                if ( text.length() )
+                if ( !text.empty() )
                     return true;
             }
             return false;
@@ -258,15 +260,15 @@ bool wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
             if ( propertyGrid->GetColumnCount() <= 2 )
             {
                 wxString unitsString = property->GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
-                if ( unitsString.length() )
+                if ( !unitsString.empty() )
                     text = wxString::Format(wxS("%s %s"), text.c_str(), unitsString.c_str() );
             }
         }
 
-        if ( text.length() == 0 )
+        if ( text.empty() )
         {
             text = property->GetHintText();
-            if ( text.length() > 0 )
+            if ( !text.empty() )
             {
                 res = true;
 
@@ -499,6 +501,23 @@ void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState,
     wxPGProperty* parent = m_parent;
     bool parentIsRoot = parent->IsKindOf(CLASSINFO(wxPGRootProperty));
 
+    //
+    // Convert invalid cells to default ones in this grid
+    for ( unsigned int i=0; i<m_cells.size(); i++ )
+    {
+        wxPGCell& cell = m_cells[i];
+        if ( cell.IsInvalid() )
+        {
+            const wxPGCell& propDefCell = propgrid->GetPropertyDefaultCell();
+            const wxPGCell& catDefCell = propgrid->GetCategoryDefaultCell();
+
+            if ( !HasFlag(wxPG_PROP_CATEGORY) )
+                cell = propDefCell;
+            else
+                cell = catDefCell;
+        }
+    }
+
     m_parentState = pageState;
 
 #if wxPG_COMPATIBILITY_1_4
@@ -621,6 +640,27 @@ void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState,
     }
 }
 
+void wxPGProperty::OnDetached(wxPropertyGridPageState* WXUNUSED(state),
+                              wxPropertyGrid* propgrid)
+{
+    if ( propgrid )
+    {
+        const wxPGCell& propDefCell = propgrid->GetPropertyDefaultCell();
+        const wxPGCell& catDefCell = propgrid->GetCategoryDefaultCell();
+
+        // Make default cells invalid
+        for ( unsigned int i=0; i<m_cells.size(); i++ )
+        {
+            wxPGCell& cell = m_cells[i];
+            if ( cell.IsSameAs(propDefCell) ||
+                 cell.IsSameAs(catDefCell) )
+            {
+                cell.UnRef();
+            }
+        }
+    }
+}
+
 wxPGProperty::wxPGProperty()
     : wxObject()
 {
@@ -677,7 +717,7 @@ wxString wxPGProperty::GetName() const
 {
     wxPGProperty* parent = GetParent();
 
-    if ( !m_name.length() || !parent || parent->IsCategory() || parent->IsRoot() )
+    if ( m_name.empty() || !parent || parent->IsCategory() || parent->IsRoot() )
         return m_name;
 
     return m_parent->GetName() + wxS(".") + m_name;
@@ -886,7 +926,7 @@ void wxPGProperty::DoGenerateComposedValue( wxString& text,
             (*childResults)[curChild->GetName()] = s;
 
         bool skip = false;
-        if ( (argFlags & wxPG_UNEDITABLE_COMPOSITE_FRAGMENT) && !s.length() )
+        if ( (argFlags & wxPG_UNEDITABLE_COMPOSITE_FRAGMENT) && s.empty() )
             skip = true;
 
         if ( !curChild->GetChildCount() || skip )
@@ -1134,7 +1174,7 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
 
                     token = text.substr(startPos,pos-startPos-1);
 
-                    if ( !token.length() )
+                    if ( token.empty() )
                         break;
 
                     const wxPGProperty* child = Item(curChild);
@@ -1525,14 +1565,17 @@ void wxPGProperty::EnsureCells( unsigned int column )
         wxPropertyGrid* pg = GetGrid();
         wxPGCell defaultCell;
 
-        // Work around possible VC6 bug by using intermediate variables
-        const wxPGCell& propDefCell = pg->GetPropertyDefaultCell();
-        const wxPGCell& catDefCell = pg->GetCategoryDefaultCell();
+        if ( pg )
+        {
+            // Work around possible VC6 bug by using intermediate variables
+            const wxPGCell& propDefCell = pg->GetPropertyDefaultCell();
+            const wxPGCell& catDefCell = pg->GetCategoryDefaultCell();
 
-        if ( !HasFlag(wxPG_PROP_CATEGORY) )
-            defaultCell = propDefCell;
-        else
-            defaultCell = catDefCell;
+            if ( !HasFlag(wxPG_PROP_CATEGORY) )
+                defaultCell = propDefCell;
+            else
+                defaultCell = catDefCell;
+        }
 
         // TODO: Replace with resize() call
         unsigned int cellCountMax = column+1;
@@ -1807,7 +1850,7 @@ wxString wxPGProperty::GetFlagsAsString( FlagType flagsMask ) const
         {
             const wxChar* fs = gs_propFlagToString[i];
             wxASSERT(fs);
-            if ( s.length() )
+            if ( !s.empty() )
                 s << wxS("|");
             s << fs;
         }
@@ -2056,19 +2099,23 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp )
 
         if ( imSz.y != maxSz.y )
         {
-            // Create a memory DC
+        #if wxUSE_IMAGE
+            // Here we use high-quality wxImage scaling functions available
+            wxImage img = bmp.ConvertToImage();
+            double scaleY = (double)maxSz.y / (double)imSz.y;
+            img.Rescale(((double)bmp.GetWidth())*scaleY,
+                        ((double)bmp.GetHeight())*scaleY,
+                        wxIMAGE_QUALITY_HIGH);
+            wxBitmap* bmpNew = new wxBitmap(img, 32);
+        #else
+            // This is the old, deprecated method of scaling the image
             wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth());
-
             wxMemoryDC dc;
             dc.SelectObject(*bmpNew);
-
-            // Scale
-            // FIXME: This is ugly - use image or wait for scaling patch.
             double scaleY = (double)maxSz.y / (double)imSz.y;
-
             dc.SetUserScale(scaleY, scaleY);
-
             dc.DrawBitmap(bmp, 0, 0);
+        #endif
 
             m_valueBitmap = bmpNew;
         }
@@ -2285,9 +2332,9 @@ void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
     else
         allChildrenSpecified = true;
 
-    wxVariant childValue = list[0];
     unsigned int i;
     unsigned int n = 0;
+    wxVariant childValue = list[n];
 
     //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());