// Created: 2008-08-23
// RCS-ID: $Id$
// Copyright: (c) Jaakko Salli
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/intl.h"
#endif
+#include "wx/image.h"
+
#include "wx/propgrid/propgrid.h"
{
text = propertyGrid->GetCommonValueLabel(cmnVal);
DrawText( dc, rect, 0, text );
- if ( text.length() )
+ if ( !text.empty() )
return true;
}
return false;
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;
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
}
}
+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()
{
{
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;
int wxPGProperty::Index( const wxPGProperty* p ) const
{
- for ( unsigned int i = 0; i<m_children.size(); i++ )
- {
- if ( p == m_children[i] )
- return i;
- }
- return wxNOT_FOUND;
+ return wxPGFindInVector(m_children, p);
}
bool wxPGProperty::ValidateValue( wxVariant& WXUNUSED(value), wxPGValidationInfo& WXUNUSED(validationInfo) ) const
(*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 )
token = text.substr(startPos,pos-startPos-1);
- if ( !token.length() )
+ if ( token.empty() )
break;
const wxPGProperty* child = Item(curChild);
}
i++;
}
+
+ // Always call OnSetValue() for a parent property (do not call it
+ // here if the value is non-null because it will then be called
+ // below)
+ if ( value.IsNull() )
+ OnSetValue();
}
if ( !value.IsNull() )
return wxVariant();
}
+void wxPGProperty::Enable( bool enable )
+{
+ wxPropertyGrid* pg = GetGrid();
+
+ // Preferably call the version in the owning wxPropertyGrid,
+ // since it handles the editor de-activation.
+ if ( pg )
+ pg->EnableProperty(this, enable);
+ else
+ DoEnable(enable);
+}
+
+void wxPGProperty::DoEnable( bool enable )
+{
+ if ( enable )
+ ClearFlag(wxPG_PROP_DISABLED);
+ else
+ SetFlag(wxPG_PROP_DISABLED);
+
+ // Apply same to sub-properties as well
+ unsigned int i;
+ for ( i = 0; i < GetChildCount(); i++ )
+ Item(i)->DoEnable( enable );
+}
+
void wxPGProperty::EnsureCells( unsigned int column )
{
if ( column >= m_cells.size() )
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;
{
const wxChar* fs = gs_propFlagToString[i];
wxASSERT(fs);
- if ( s.length() )
+ if ( !s.empty() )
s << wxS("|");
s << fs;
}
}
}
-bool wxPGProperty::SetChoices( wxPGChoices& choices )
+bool wxPGProperty::SetChoices( const wxPGChoices& choices )
{
// Property must be de-selected first (otherwise choices in
// the control would be de-synced with true choices)
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;
}
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());