]> git.saurik.com Git - wxWidgets.git/blobdiff - src/propgrid/property.cpp
Add a few missing appearance screenshots for the manual.
[wxWidgets.git] / src / propgrid / property.cpp
index 4a90d9ab3b4e6e05627a65b0dd0cdb3906646c65..bafa791fc48f0383369fece897d4270cba8aeeb7 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      Jaakko Salli
 // Modified by:
 // Created:     2008-08-23
 // Author:      Jaakko Salli
 // Modified by:
 // Created:     2008-08-23
-// RCS-ID:      $Id$
 // Copyright:   (c) Jaakko Salli
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 // Copyright:   (c) Jaakko Salli
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -24,6 +23,7 @@
     #include "wx/hash.h"
     #include "wx/string.h"
     #include "wx/log.h"
     #include "wx/hash.h"
     #include "wx/string.h"
     #include "wx/log.h"
+    #include "wx/math.h"
     #include "wx/event.h"
     #include "wx/window.h"
     #include "wx/panel.h"
     #include "wx/event.h"
     #include "wx/window.h"
     #include "wx/panel.h"
@@ -35,6 +35,8 @@
     #include "wx/intl.h"
 #endif
 
     #include "wx/intl.h"
 #endif
 
+#include "wx/image.h"
+
 #include "wx/propgrid/propgrid.h"
 
 
 #include "wx/propgrid/propgrid.h"
 
 
@@ -45,7 +47,7 @@
 
 #if wxPG_COMPATIBILITY_1_4
 
 
 #if wxPG_COMPATIBILITY_1_4
 
-// Used to establish backwards compatiblity
+// Used to establish backwards compatibility
 const char* g_invalidStringContent = "@__TOTALLY_INVALID_STRING__@";
 
 #endif
 const char* g_invalidStringContent = "@__TOTALLY_INVALID_STRING__@";
 
 #endif
@@ -156,7 +158,7 @@ int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell&
         dc.SetFont(font);
 
     const wxBitmap& bmp = cell.GetBitmap();
         dc.SetFont(font);
 
     const wxBitmap& bmp = cell.GetBitmap();
-    if ( bmp.Ok() &&
+    if ( bmp.IsOk() &&
         // Do not draw oversized bitmap outside choice popup
          ((flags & ChoicePopup) || bmp.GetHeight() < rect.height )
         )
         // Do not draw oversized bitmap outside choice popup
          ((flags & ChoicePopup) || bmp.GetHeight() < rect.height )
         )
@@ -274,7 +276,7 @@ bool wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
                     propertyGrid->GetCellDisabledTextColour();
                 dc.SetTextForeground(hCol);
 
                     propertyGrid->GetCellDisabledTextColour();
                 dc.SetTextForeground(hCol);
 
-                // Must make the editor NULL to override it's own rendering
+                // Must make the editor NULL to override its own rendering
                 // code.
                 editor = NULL;
             }
                 // code.
                 editor = NULL;
             }
@@ -325,7 +327,7 @@ wxSize wxPGDefaultRenderer::GetImageSize( const wxPGProperty* property,
         {
             wxBitmap* bmp = property->GetValueImage();
 
         {
             wxBitmap* bmp = property->GetValueImage();
 
-            if ( bmp && bmp->Ok() )
+            if ( bmp && bmp->IsOk() )
                 return wxSize(bmp->GetWidth(),bmp->GetHeight());
         }
     }
                 return wxSize(bmp->GetWidth(),bmp->GetHeight());
         }
     }
@@ -497,7 +499,7 @@ void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState,
     // (so propgrid can be NULL, too).
 
     wxPGProperty* parent = m_parent;
     // (so propgrid can be NULL, too).
 
     wxPGProperty* parent = m_parent;
-    bool parentIsRoot = parent->IsKindOf(CLASSINFO(wxPGRootProperty));
+    bool parentIsRoot = parent->IsKindOf(wxCLASSINFO(wxPGRootProperty));
 
     //
     // Convert invalid cells to default ones in this grid
 
     //
     // Convert invalid cells to default ones in this grid
@@ -1032,7 +1034,7 @@ bool wxPGProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(argF
 }
 
 // Convert semicolon delimited tokens into child values.
 }
 
 // Convert semicolon delimited tokens into child values.
-bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const
+bool wxPGProperty::StringToValue( wxVariant& v, const wxString& text, int argFlags ) const
 {
     if ( !GetChildCount() )
         return false;
 {
     if ( !GetChildCount() )
         return false;
@@ -1237,7 +1239,7 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
     }
 
     if ( changed )
     }
 
     if ( changed )
-        variant = list;
+        v = list;
 
     return changed;
 }
 
     return changed;
 }
@@ -1295,7 +1297,7 @@ void wxPGProperty::OnCustomPaint( wxDC& dc,
 {
     wxBitmap* bmp = m_valueBitmap;
 
 {
     wxBitmap* bmp = m_valueBitmap;
 
-    wxCHECK_RET( bmp && bmp->Ok(), wxT("invalid bitmap") );
+    wxCHECK_RET( bmp && bmp->IsOk(), wxT("invalid bitmap") );
 
     wxCHECK_RET( rect.x >= 0, wxT("unexpected measure call") );
 
 
     wxCHECK_RET( rect.x >= 0, wxT("unexpected measure call") );
 
@@ -2018,11 +2020,11 @@ const wxPGEditor* wxPGProperty::GetEditorClass() const
     if ( GetDisplayedCommonValueCount() )
     {
         // TextCtrlAndButton -> ComboBoxAndButton
     if ( GetDisplayedCommonValueCount() )
     {
         // TextCtrlAndButton -> ComboBoxAndButton
-        if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor)) )
+        if ( wxDynamicCast(editor, wxPGTextCtrlAndButtonEditor) )
             editor = wxPGEditor_ChoiceAndButton;
 
         // TextCtrl -> ComboBox
             editor = wxPGEditor_ChoiceAndButton;
 
         // TextCtrl -> ComboBox
-        else if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlEditor)) )
+        else if ( wxDynamicCast(editor, wxPGTextCtrlEditor) )
             editor = wxPGEditor_ComboBox;
     }
 
             editor = wxPGEditor_ComboBox;
     }
 
@@ -2089,7 +2091,7 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp )
 {
     delete m_valueBitmap;
 
 {
     delete m_valueBitmap;
 
-    if ( &bmp && bmp.Ok() )
+    if ( &bmp && bmp.IsOk() )
     {
         // Resize the image
         wxSize maxSz = GetGrid()->GetImageSize();
     {
         // Resize the image
         wxSize maxSz = GetGrid()->GetImageSize();
@@ -2097,19 +2099,23 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp )
 
         if ( imSz.y != maxSz.y )
         {
 
         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(wxRound(bmp.GetWidth()*scaleY),
+                        wxRound(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());
             wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth());
-
             wxMemoryDC dc;
             dc.SelectObject(*bmpNew);
             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;
             double scaleY = (double)maxSz.y / (double)imSz.y;
-
             dc.SetUserScale(scaleY, scaleY);
             dc.SetUserScale(scaleY, scaleY);
-
             dc.DrawBitmap(bmp, 0, 0);
             dc.DrawBitmap(bmp, 0, 0);
+        #endif
 
             m_valueBitmap = bmpNew;
         }
 
             m_valueBitmap = bmpNew;
         }
@@ -2192,7 +2198,7 @@ int wxPGProperty::GetY2( int lh ) const
     for ( parent = GetParent(); parent != NULL; parent = child->GetParent() )
     {
         if ( !parent->IsExpanded() )
     for ( parent = GetParent(); parent != NULL; parent = child->GetParent() )
     {
         if ( !parent->IsExpanded() )
-            return -1;
+            return parent->GetY2(lh);
         y += parent->GetChildrenHeight(lh, child->GetIndexInParent());
         y += lh;
         child = parent;
         y += parent->GetChildrenHeight(lh, child->GetIndexInParent());
         y += lh;
         child = parent;
@@ -2326,9 +2332,9 @@ void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
     else
         allChildrenSpecified = true;
 
     else
         allChildrenSpecified = true;
 
-    wxVariant childValue = list[0];
     unsigned int i;
     unsigned int n = 0;
     unsigned int i;
     unsigned int n = 0;
+    wxVariant childValue = list[n];
 
     //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
 
 
     //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
 
@@ -2563,6 +2569,25 @@ void wxPGProperty::DeleteChildren()
     }
 }
 
     }
 }
 
+bool wxPGProperty::IsChildSelected( bool recursive ) const
+{
+    size_t i;
+    for ( i = 0; i < GetChildCount(); i++ )
+    {
+        wxPGProperty* child = Item(i);
+
+        // Test child
+        if ( m_parentState->DoIsPropertySelected( child ) )
+            return true;
+
+        // Test sub-childs
+        if ( recursive && child->IsChildSelected( recursive ) )
+            return true;
+    }
+
+    return false;
+}
+
 wxVariant wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue),
                                       int WXUNUSED(childIndex),
                                       wxVariant& WXUNUSED(childValue) ) const
 wxVariant wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue),
                                       int WXUNUSED(childIndex),
                                       wxVariant& WXUNUSED(childValue) ) const