}
#endif // #if wxUSE_VALIDATORS
- /** Updates property value in case there were last minute
- changes. If value was unspecified, it will be set to default.
- Use only for properties that have TextCtrl-based editor.
- @remarks
- If you have code similar to
- @code
- // Update the value in case of last minute changes
- if ( primary && propgrid->IsEditorsValueModified() )
- GetEditorClass()->CopyValueFromControl( this, primary );
- @endcode
- in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
- then replace it with call to this method.
- @return
- True if value changed.
- */
- bool PrepareValueForDialogEditing( wxPropertyGrid* propgrid );
-
#ifndef SWIG
/** Returns client data (void*) of a property.
*/
/** Returns background colour of margin. */
wxColour GetMarginColour() const { return m_colMargin; }
+ /**
+ Returns most up-to-date value of selected property. This will return
+ value different from GetSelectedProperty()->GetValue() only when text
+ editor is activate and string edited by user represents valid,
+ uncommitted property value.
+ */
+ wxVariant GetPendingEditedValue();
+
/** Returns cell background colour of a property. */
wxColour GetPropertyBackgroundColour( wxPGPropArg id ) const;
virtual bool DoPropertyChanged( wxPGProperty* p,
unsigned int selFlags = 0 );
- /**
- Runs all validation functionality (includes sending wxEVT_PG_CHANGING).
- Returns true if all tests passed.
- */
- virtual bool PerformValidation( wxPGProperty* p, wxVariant& pendingValue );
-
/** Called when validation for given property fails.
@param invalidValue
Value which failed in validation.
*/
virtual wxPropertyGridPageState* CreateState() const;
+ enum PerformValidationFlags
+ {
+ SendEvtChanging = 0x0001,
+ IsStandaloneValidation = 0x0002 // Not called in response to event
+ };
+
+ /**
+ Runs all validation functionality (includes sending wxEVT_PG_CHANGING).
+ Returns true if all tests passed. Implement in derived class to
+ add additional validation behavior.
+ */
+ virtual bool PerformValidation( wxPGProperty* p,
+ wxVariant& pendingValue,
+ int flags = SendEvtChanging );
+
#ifndef DOXYGEN
public:
@code
virtual bool OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
{
- // Update property value from editor, if necessary
- PrepareValueForDialogEditing(propGrid);
-
wxSize dialogSize(...size of your dialog...);
wxPoint dlgPos = propGrid->GetGoodEditorDialogPosition(this,
*/
wxPGProperty* Item( size_t i ) const;
- /**
- Updates property value in case there were last minute
- changes. If value was unspecified, it will be set to default.
- Use only for properties that have TextCtrl-based editor.
-
- @remarks If you have code similar to
- @code
- // Update the value in case of last minute changes
- if ( primary && propgrid->IsEditorsValueModified() )
- GetEditorClass()->CopyValueFromControl( this, primary );
- @endcode
- in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
- then replace it with call to this method.
-
- @return Returns @true if value changed.
- */
- bool PrepareValueForDialogEditing( wxPropertyGrid* propgrid );
-
/**
If property's editor is active, then update it's value.
*/
*/
wxColour GetMarginColour() const;
+ /**
+ Returns most up-to-date value of selected property. This will return
+ value different from GetSelectedProperty()->GetValue() only when text
+ editor is activate and string edited by user represents valid,
+ uncommitted property value.
+ */
+ wxVariant GetPendingEditedValue();
+
/**
Returns cell background colour of a property.
*/
{
if ( propgrid->IsMainButtonEvent(event) )
{
- // Update value from last minute changes
- PrepareValueForDialogEditing(propgrid);
+ wxVariant useValue = propgrid->GetPendingEditedValue();
wxFontData fontData;
- fontData << m_value_wxFontData;
+ fontData << useValue;
fontData.SetInitialFont(fontData.GetChosenFont());
{
if ( propgrid->IsMainButtonEvent(event) )
{
- wxArrayDouble& value = wxArrayDoubleRefFromVariant(m_value);
-
// Update the value in case of last minute changes
- PrepareValueForDialogEditing(propgrid);
+ wxVariant useValue = propgrid->GetPendingEditedValue();
+
+ wxArrayDouble& value = wxArrayDoubleRefFromVariant(useValue);
// Create editor dialog.
wxArrayDoubleEditorDialog dlg;
if ( propgrid->IsMainButtonEvent(event) )
{
// Update value from last minute changes
- PrepareValueForDialogEditing(propgrid);
+ wxVariant useValue = propgrid->GetPendingEditedValue();
wxFontData data;
wxFont font;
- font << m_value;
+ font << useValue;
data.SetInitialFont( font );
data.SetColour(*wxBLACK);
if ( propgrid->IsMainButtonEvent(event) )
{
// Update the value
- PrepareValueForDialogEditing(propgrid);
+ wxVariant useValue = propgrid->GetPendingEditedValue();
wxArrayString labels = m_choices.GetLabels();
unsigned int choiceCount;
dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
- wxArrayString strings = m_value.GetArrayString();
+ wxArrayString strings = useValue.GetArrayString();
wxArrayString extraStrings;
dlg.SetSelections(m_choices.GetIndicesForStrings(strings, &extraStrings));
return false;
}
-bool wxPGProperty::PrepareValueForDialogEditing( wxPropertyGrid* propGrid )
-{
- return propGrid->CommitChangesFromEditor();
-}
-
-
bool wxPGProperty::RecreateEditor()
{
wxPropertyGrid* pg = GetGrid();
// -----------------------------------------------------------------------
-bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue )
+bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue,
+ int flags )
{
//
// Runs all validation functionality.
wxVariant evtChangingValue = value;
- // FIXME: After proper ValueToString()s added, remove
- // this. It is just a temporary fix, as evt_changing
- // will simply not work for wxPG_PROP_COMPOSED_VALUE
- // (unless it is selected, and textctrl editor is open).
- if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
+ if ( flags & SendEvtChanging )
{
- evtChangingProperty = baseChangedProperty;
- if ( evtChangingProperty != p )
+ // FIXME: After proper ValueToString()s added, remove
+ // this. It is just a temporary fix, as evt_changing
+ // will simply not work for wxPG_PROP_COMPOSED_VALUE
+ // (unless it is selected, and textctrl editor is open).
+ if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
{
- evtChangingProperty->AdaptListToValue( bcpPendingList, &evtChangingValue );
- }
- else
- {
- evtChangingValue = pendingValue;
+ evtChangingProperty = baseChangedProperty;
+ if ( evtChangingProperty != p )
+ {
+ evtChangingProperty->AdaptListToValue( bcpPendingList, &evtChangingValue );
+ }
+ else
+ {
+ evtChangingValue = pendingValue;
+ }
}
- }
- if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
- {
- if ( changedProperty == m_selected )
- {
- wxWindow* editor = GetEditorControl();
- wxASSERT( editor->IsKindOf(CLASSINFO(wxTextCtrl)) );
- evtChangingValue = wxStaticCast(editor, wxTextCtrl)->GetValue();
- }
- else
+ if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
{
- wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
+ if ( changedProperty == m_selected )
+ {
+ wxWindow* editor = GetEditorControl();
+ wxASSERT( editor->IsKindOf(CLASSINFO(wxTextCtrl)) );
+ evtChangingValue = wxStaticCast(editor, wxTextCtrl)->GetValue();
+ }
+ else
+ {
+ wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
+ }
}
}
return false;
}
- // SendEvent returns true if event was vetoed
- if ( SendEvent( wxEVT_PG_CHANGING, evtChangingProperty, &evtChangingValue, 0 ) )
- return false;
+ if ( flags & SendEvtChanging )
+ {
+ // SendEvent returns true if event was vetoed
+ if ( SendEvent( wxEVT_PG_CHANGING, evtChangingProperty, &evtChangingValue, 0 ) )
+ return false;
+ }
+
+ if ( flags & IsStandaloneValidation )
+ {
+ // If called in 'generic' context, we need to reset
+ // m_chgInfo_changedProperty and write back translated value.
+ m_chgInfo_changedProperty = NULL;
+ pendingValue = value;
+ }
return true;
}
// -----------------------------------------------------------------------
+wxVariant wxPropertyGrid::GetPendingEditedValue()
+{
+ wxPGProperty* prop = GetSelectedProperty();
+
+ if ( !prop )
+ return wxNullVariant;
+
+ wxTextCtrl* tc = GetEditorTextCtrl();
+ wxVariant value = prop->GetValue();
+
+ if ( !tc || !IsEditorsValueModified() )
+ return value;
+
+ if ( !prop->StringToValue(value, tc->GetValue()) )
+ return value;
+
+ if ( !PerformValidation(prop, value, IsStandaloneValidation) )
+ return prop->GetValue();
+
+ return value;
+}
+
+// -----------------------------------------------------------------------
+
// Runs wxValidator for the selected property
bool wxPropertyGrid::DoEditorValidate()
{
bool wxDirProperty::OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
{
// Update property value from editor, if necessary
- PrepareValueForDialogEditing(propGrid);
-
wxSize dlg_sz(300,400);
wxDirDialog dlg( propGrid,
if ( propGrid->IsMainButtonEvent(event) )
{
// Update the value
- PrepareValueForDialogEditing(propGrid);
+ wxVariant useValue = propGrid->GetPendingEditedValue();
- wxString val1 = GetValueAsString(0);
+ wxString val1 = useValue.GetString();
wxString val_orig = val1;
wxString value;
const wxChar* cbt )
{
// Update the value
- PrepareValueForDialogEditing(propGrid);
+ wxVariant useValue = propGrid->GetPendingEditedValue();
if ( !propGrid->EditorValidate() )
return false;
if ( strEdDlg )
strEdDlg->SetCustomButton(cbt, this);
- dlg->SetDialogValue( wxVariant(m_value) );
+ dlg->SetDialogValue( useValue );
dlg->Create(propGrid, wxEmptyString, m_label);
#if !wxPG_SMALL_SCREEN