// Author: Jaakko Salli
// Modified by:
// 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/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/intl.h"
#endif
+#include "wx/image.h"
+
#include "wx/propgrid/propgrid.h"
#if wxPG_COMPATIBILITY_1_4
-// Used to establish backwards compatiblity
+// Used to establish backwards compatibility
const char* g_invalidStringContent = "@__TOTALLY_INVALID_STRING__@";
#endif
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 )
)
{
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;
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;
}
{
wxBitmap* bmp = property->GetValueImage();
- if ( bmp && bmp->Ok() )
+ if ( bmp && bmp->IsOk() )
return wxSize(bmp->GetWidth(),bmp->GetHeight());
}
}
// (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
+ 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;
}
}
+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 )
}
// 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;
token = text.substr(startPos,pos-startPos-1);
- if ( !token.length() )
+ if ( token.empty() )
break;
const wxPGProperty* child = Item(curChild);
}
if ( changed )
- variant = list;
+ v = list;
return changed;
}
{
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") );
}
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 ( GetDisplayedCommonValueCount() )
{
// TextCtrlAndButton -> ComboBoxAndButton
- if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor)) )
+ if ( wxDynamicCast(editor, wxPGTextCtrlAndButtonEditor) )
editor = wxPGEditor_ChoiceAndButton;
// TextCtrl -> ComboBox
- else if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlEditor)) )
+ else if ( wxDynamicCast(editor, wxPGTextCtrlEditor) )
editor = wxPGEditor_ComboBox;
}
return editor;
}
+bool wxPGProperty::Hide( bool hide, int flags )
+{
+ wxPropertyGrid* pg = GetGrid();
+ if ( pg )
+ return pg->HideProperty(this, hide, flags);
+
+ return DoHide( hide, flags );
+}
+
+bool wxPGProperty::DoHide( bool hide, int flags )
+{
+ if ( !hide )
+ ClearFlag( wxPG_PROP_HIDDEN );
+ else
+ SetFlag( wxPG_PROP_HIDDEN );
+
+ if ( flags & wxPG_RECURSE )
+ {
+ unsigned int i;
+ for ( i = 0; i < GetChildCount(); i++ )
+ Item(i)->DoHide(hide, flags | wxPG_RECURSE_STARTS);
+ }
+
+ return true;
+}
+
bool wxPGProperty::HasVisibleChildren() const
{
unsigned int i;
{
delete m_valueBitmap;
- if ( &bmp && bmp.Ok() )
+ if ( &bmp && bmp.IsOk() )
{
// Resize the image
wxSize maxSz = GetGrid()->GetImageSize();
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());
-
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;
}
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;
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());
}
}
+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