]> git.saurik.com Git - wxWidgets.git/blobdiff - src/propgrid/property.cpp
simpler define handling
[wxWidgets.git] / src / propgrid / property.cpp
index a3b35d4f27db9c5e86c460f04afe597b1c5fb04f..d670542dfa5e76799d2cffd65820949be4f49791 100644 (file)
@@ -94,8 +94,6 @@ wxSize wxPGCellRenderer::GetImageSize( const wxPGProperty* WXUNUSED(property),
 void wxPGCellRenderer::DrawText( wxDC& dc, const wxRect& rect,
                                  int xOffset, const wxString& text ) const
 {
 void wxPGCellRenderer::DrawText( wxDC& dc, const wxRect& rect,
                                  int xOffset, const wxString& text ) const
 {
-    if ( xOffset )
-        xOffset += wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
     dc.DrawText( text,
                  rect.x+xOffset+wxPG_XBEFORETEXT,
                  rect.y+((rect.height-dc.GetCharHeight())/2) );
     dc.DrawText( text,
                  rect.x+xOffset+wxPG_XBEFORETEXT,
                  rect.y+((rect.height-dc.GetCharHeight())/2) );
@@ -106,9 +104,6 @@ void wxPGCellRenderer::DrawEditorValue( wxDC& dc, const wxRect& rect,
                                         wxPGProperty* property,
                                         const wxPGEditor* editor ) const
 {
                                         wxPGProperty* property,
                                         const wxPGEditor* editor ) const
 {
-    if ( xOffset )
-        xOffset += wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
-
     int yOffset = ((rect.height-dc.GetCharHeight())/2);
 
     if ( editor )
     int yOffset = ((rect.height-dc.GetCharHeight())/2);
 
     if ( editor )
@@ -135,7 +130,7 @@ void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC& dc, int x, int y, int w,
 
 int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell& cell, int flags ) const
 {
 
 int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell& cell, int flags ) const
 {
-    int imageOffset = 0;
+    int imageWidth = 0;
 
     // If possible, use cell colours
     if ( !(flags & DontUseCellBgCol) )
 
     // If possible, use cell colours
     if ( !(flags & DontUseCellBgCol) )
@@ -164,10 +159,10 @@ int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell&
                        rect.x + wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1,
                        rect.y + wxPG_CUSTOM_IMAGE_SPACINGY,
                        true );
                        rect.x + wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1,
                        rect.y + wxPG_CUSTOM_IMAGE_SPACINGY,
                        true );
-        imageOffset = bmp.GetWidth();
+        imageWidth = bmp.GetWidth();
     }
 
     }
 
-    return imageOffset;
+    return imageWidth;
 }
 
 // -----------------------------------------------------------------------
 }
 
 // -----------------------------------------------------------------------
@@ -196,12 +191,12 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
     const wxPGCell* cell = NULL;
 
     wxString text;
     const wxPGCell* cell = NULL;
 
     wxString text;
-    int imageOffset = 0;
+    int imageWidth = 0;
     int preDrawFlags = flags;
 
     property->GetDisplayInfo(column, item, flags, &text, &cell);
 
     int preDrawFlags = flags;
 
     property->GetDisplayInfo(column, item, flags, &text, &cell);
 
-    imageOffset = PreDrawCell( dc, rect, *cell, preDrawFlags );
+    imageWidth = PreDrawCell( dc, rect, *cell, preDrawFlags );
 
     if ( column == 1 )
     {
 
     if ( column == 1 )
     {
@@ -231,7 +226,7 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
 
                 property->OnCustomPaint( dc, imageRect, paintdata );
 
 
                 property->OnCustomPaint( dc, imageRect, paintdata );
 
-                imageOffset = paintdata.m_drawnWidth;
+                imageWidth = paintdata.m_drawnWidth;
             }
 
             text = property->GetValueAsString();
             }
 
             text = property->GetValueAsString();
@@ -257,6 +252,8 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
         }
     }
 
         }
     }
 
+    int imageOffset = property->GetImageOffset(imageWidth);
+
     DrawEditorValue( dc, rect, imageOffset, text, property, editor );
 
     // active caption gets nice dotted rectangle
     DrawEditorValue( dc, rect, imageOffset, text, property, editor );
 
     // active caption gets nice dotted rectangle
@@ -264,8 +261,11 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
     {
         if ( flags & Selected )
         {
     {
         if ( flags & Selected )
         {
-            if ( imageOffset > 0 )
-                imageOffset += wxCC_CUSTOM_IMAGE_MARGIN2 + 4;
+            if ( imageWidth > 0 )
+            {
+                imageOffset -= DEFAULT_IMAGE_OFFSET_INCREMENT;
+                imageWidth += wxCC_CUSTOM_IMAGE_MARGIN2 + 4;
+            }
 
             DrawCaptionSelectionRect( dc,
                                       rect.x+wxPG_XBEFORETEXT-wxPG_CAPRECTXMARGIN+imageOffset,
 
             DrawCaptionSelectionRect( dc,
                                       rect.x+wxPG_XBEFORETEXT-wxPG_CAPRECTXMARGIN+imageOffset,
@@ -539,10 +539,12 @@ void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState,
     if ( GetChildCount() )
     {
         // Check parental flags
     if ( GetChildCount() )
     {
         // Check parental flags
-        wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS),
-                      "Call SetFlag(wxPG_PROP_MISC_PARENT) or"
-                      "SetFlag(wxPG_PROP_AGGREGATE) before calling"
-                      "wxPGProperty::AddChild()." );
+        wxASSERT_MSG( ((m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
+                            wxPG_PROP_AGGREGATE) ||
+                      ((m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
+                            wxPG_PROP_MISC_PARENT),
+                      "wxPGProperty parental flags set incorrectly at "
+                      "this time" );
 
         if ( HasFlag(wxPG_PROP_AGGREGATE) )
         {
 
         if ( HasFlag(wxPG_PROP_AGGREGATE) )
         {
@@ -1170,6 +1172,22 @@ wxSize wxPGProperty::OnMeasureImage( int WXUNUSED(item) ) const
     return wxSize(0,0);
 }
 
     return wxSize(0,0);
 }
 
+int wxPGProperty::GetImageOffset( int imageWidth ) const
+{
+    int imageOffset = 0;
+
+    if ( imageWidth )
+    {
+        // Do not increment offset too much for wide images
+        if ( imageWidth <= (wxPG_CUSTOM_IMAGE_WIDTH+5) )
+            imageOffset = imageWidth + DEFAULT_IMAGE_OFFSET_INCREMENT;
+        else
+            imageOffset = imageWidth + 1;
+    }
+
+    return imageOffset;
+}
+
 wxPGCellRenderer* wxPGProperty::GetCellRenderer( int WXUNUSED(column) ) const
 {
     return wxPGGlobalVars->m_defaultRenderer;
 wxPGCellRenderer* wxPGProperty::GetCellRenderer( int WXUNUSED(column) ) const
 {
     return wxPGGlobalVars->m_defaultRenderer;
@@ -1903,7 +1921,7 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp )
         wxSize maxSz = GetGrid()->GetImageSize();
         wxSize imSz(bmp.GetWidth(),bmp.GetHeight());
 
         wxSize maxSz = GetGrid()->GetImageSize();
         wxSize imSz(bmp.GetWidth(),bmp.GetHeight());
 
-        if ( imSz.x != maxSz.x || imSz.y != maxSz.y )
+        if ( imSz.y != maxSz.y )
         {
             // Create a memory DC
             wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth());
         {
             // Create a memory DC
             wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth());
@@ -1913,12 +1931,11 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp )
 
             // Scale
             // FIXME: This is ugly - use image or wait for scaling patch.
 
             // Scale
             // FIXME: This is ugly - use image or wait for scaling patch.
-            double scaleX = (double)maxSz.x / (double)imSz.x;
             double scaleY = (double)maxSz.y / (double)imSz.y;
 
             double scaleY = (double)maxSz.y / (double)imSz.y;
 
-            dc.SetUserScale(scaleX,scaleY);
+            dc.SetUserScale(scaleY, scaleY);
 
 
-            dc.DrawBitmap( bmp, 0, 0 );
+            dc.DrawBitmap(bmp, 0, 0);
 
             m_valueBitmap = bmpNew;
         }
 
             m_valueBitmap = bmpNew;
         }
@@ -2019,7 +2036,8 @@ int wxPGProperty::GetY() const
 }
 
 // This is used by Insert etc.
 }
 
 // This is used by Insert etc.
-void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
+void wxPGProperty::DoAddChild( wxPGProperty* prop, int index,
+                               bool correct_mode )
 {
     if ( index < 0 || (size_t)index >= m_children.size() )
     {
 {
     if ( index < 0 || (size_t)index >= m_children.size() )
     {
@@ -2035,14 +2053,15 @@ void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
     prop->m_parent = this;
 }
 
     prop->m_parent = this;
 }
 
-// This is used by properties that have fixed sub-properties
-void wxPGProperty::AddChild( wxPGProperty* prop )
+void wxPGProperty::DoPreAddChild( int index, wxPGProperty* prop )
 {
     wxASSERT_MSG( prop->GetBaseName().length(),
 {
     wxASSERT_MSG( prop->GetBaseName().length(),
-                  "Property's children must have unique, non-empty names within their scope" );
+                  "Property's children must have unique, non-empty "
+                  "names within their scope" );
 
 
-    prop->m_arrIndex = m_children.size();
-    m_children.push_back( prop );
+    prop->m_arrIndex = index;
+    m_children.insert( m_children.begin()+index,
+                       prop );
 
     int custImgHeight = prop->OnMeasureImage().y;
     if ( custImgHeight < 0 /*|| custImgHeight > 1*/ )
 
     int custImgHeight = prop->OnMeasureImage().y;
     if ( custImgHeight < 0 /*|| custImgHeight > 1*/ )
@@ -2051,6 +2070,52 @@ void wxPGProperty::AddChild( wxPGProperty* prop )
     prop->m_parent = this;
 }
 
     prop->m_parent = this;
 }
 
+void wxPGProperty::AddPrivateChild( wxPGProperty* prop )
+{
+    if ( !(m_flags & wxPG_PROP_PARENTAL_FLAGS) )
+        SetParentalType(wxPG_PROP_AGGREGATE);
+
+    wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
+                    wxPG_PROP_AGGREGATE,
+                  "Do not mix up AddPrivateChild() calls with other "
+                  "property adders." );
+
+    DoPreAddChild( m_children.size(), prop );
+}
+
+#if wxPG_COMPATIBILITY_1_4
+void wxPGProperty::AddChild( wxPGProperty* prop )
+{
+    AddPrivateChild(prop);
+}
+#endif
+
+wxPGProperty* wxPGProperty::InsertChild( int index,
+                                         wxPGProperty* childProperty )
+{
+    if ( index < 0 )
+        index = m_children.size();
+
+    if ( m_parentState )
+    {
+        m_parentState->DoInsert(this, index, childProperty);
+    }
+    else
+    {
+        if ( !(m_flags & wxPG_PROP_PARENTAL_FLAGS) )
+            SetParentalType(wxPG_PROP_MISC_PARENT);
+
+        wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
+                        wxPG_PROP_MISC_PARENT,
+                      "Do not mix up AddPrivateChild() calls with other "
+                      "property adders." );
+
+        DoPreAddChild( index, childProperty );
+    }
+
+    return childProperty;
+}
+
 void wxPGProperty::RemoveChild( wxPGProperty* p )
 {
     wxArrayPGProperty::iterator it;
 void wxPGProperty::RemoveChild( wxPGProperty* p )
 {
     wxArrayPGProperty::iterator it;