Removed dysfunctional wxPGPropery::PrepareValueForDialogEditing(); Replaced its functionality with wxPropertyGrid::GetPendingEditedValue(); Added wxPropertyGrid::PerformValidation() flags so it can be called in generic context.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56169 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1814,23 +1814,6 @@ public:
|
|||||||
}
|
}
|
||||||
#endif // #if wxUSE_VALIDATORS
|
#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
|
#ifndef SWIG
|
||||||
/** Returns client data (void*) of a property.
|
/** Returns client data (void*) of a property.
|
||||||
*/
|
*/
|
||||||
|
@@ -832,6 +832,14 @@ public:
|
|||||||
/** Returns background colour of margin. */
|
/** Returns background colour of margin. */
|
||||||
wxColour GetMarginColour() const { return m_colMargin; }
|
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. */
|
/** Returns cell background colour of a property. */
|
||||||
wxColour GetPropertyBackgroundColour( wxPGPropArg id ) const;
|
wxColour GetPropertyBackgroundColour( wxPGPropArg id ) const;
|
||||||
|
|
||||||
@@ -1257,12 +1265,6 @@ public:
|
|||||||
virtual bool DoPropertyChanged( wxPGProperty* p,
|
virtual bool DoPropertyChanged( wxPGProperty* p,
|
||||||
unsigned int selFlags = 0 );
|
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.
|
/** Called when validation for given property fails.
|
||||||
@param invalidValue
|
@param invalidValue
|
||||||
Value which failed in validation.
|
Value which failed in validation.
|
||||||
@@ -1340,6 +1342,21 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual wxPropertyGridPageState* CreateState() const;
|
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
|
#ifndef DOXYGEN
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@@ -240,9 +240,6 @@
|
|||||||
@code
|
@code
|
||||||
virtual bool OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
|
virtual bool OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
|
||||||
{
|
{
|
||||||
// Update property value from editor, if necessary
|
|
||||||
PrepareValueForDialogEditing(propGrid);
|
|
||||||
|
|
||||||
wxSize dialogSize(...size of your dialog...);
|
wxSize dialogSize(...size of your dialog...);
|
||||||
|
|
||||||
wxPoint dlgPos = propGrid->GetGoodEditorDialogPosition(this,
|
wxPoint dlgPos = propGrid->GetGoodEditorDialogPosition(this,
|
||||||
@@ -1199,24 +1196,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
wxPGProperty* Item( size_t i ) const;
|
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.
|
If property's editor is active, then update it's value.
|
||||||
*/
|
*/
|
||||||
|
@@ -586,6 +586,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
wxColour GetMarginColour() const;
|
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.
|
Returns cell background colour of a property.
|
||||||
*/
|
*/
|
||||||
|
@@ -131,11 +131,10 @@ bool wxFontDataProperty::OnEvent( wxPropertyGrid* propgrid,
|
|||||||
{
|
{
|
||||||
if ( propgrid->IsMainButtonEvent(event) )
|
if ( propgrid->IsMainButtonEvent(event) )
|
||||||
{
|
{
|
||||||
// Update value from last minute changes
|
wxVariant useValue = propgrid->GetPendingEditedValue();
|
||||||
PrepareValueForDialogEditing(propgrid);
|
|
||||||
|
|
||||||
wxFontData fontData;
|
wxFontData fontData;
|
||||||
fontData << m_value_wxFontData;
|
fontData << useValue;
|
||||||
|
|
||||||
fontData.SetInitialFont(fontData.GetChosenFont());
|
fontData.SetInitialFont(fontData.GetChosenFont());
|
||||||
|
|
||||||
@@ -554,10 +553,10 @@ bool wxArrayDoubleProperty::OnEvent( wxPropertyGrid* propgrid,
|
|||||||
{
|
{
|
||||||
if ( propgrid->IsMainButtonEvent(event) )
|
if ( propgrid->IsMainButtonEvent(event) )
|
||||||
{
|
{
|
||||||
wxArrayDouble& value = wxArrayDoubleRefFromVariant(m_value);
|
|
||||||
|
|
||||||
// Update the value in case of last minute changes
|
// Update the value in case of last minute changes
|
||||||
PrepareValueForDialogEditing(propgrid);
|
wxVariant useValue = propgrid->GetPendingEditedValue();
|
||||||
|
|
||||||
|
wxArrayDouble& value = wxArrayDoubleRefFromVariant(useValue);
|
||||||
|
|
||||||
// Create editor dialog.
|
// Create editor dialog.
|
||||||
wxArrayDoubleEditorDialog dlg;
|
wxArrayDoubleEditorDialog dlg;
|
||||||
|
@@ -531,11 +531,11 @@ bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(prima
|
|||||||
if ( propgrid->IsMainButtonEvent(event) )
|
if ( propgrid->IsMainButtonEvent(event) )
|
||||||
{
|
{
|
||||||
// Update value from last minute changes
|
// Update value from last minute changes
|
||||||
PrepareValueForDialogEditing(propgrid);
|
wxVariant useValue = propgrid->GetPendingEditedValue();
|
||||||
|
|
||||||
wxFontData data;
|
wxFontData data;
|
||||||
wxFont font;
|
wxFont font;
|
||||||
font << m_value;
|
font << useValue;
|
||||||
data.SetInitialFont( font );
|
data.SetInitialFont( font );
|
||||||
data.SetColour(*wxBLACK);
|
data.SetColour(*wxBLACK);
|
||||||
|
|
||||||
@@ -1803,7 +1803,7 @@ bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid,
|
|||||||
if ( propgrid->IsMainButtonEvent(event) )
|
if ( propgrid->IsMainButtonEvent(event) )
|
||||||
{
|
{
|
||||||
// Update the value
|
// Update the value
|
||||||
PrepareValueForDialogEditing(propgrid);
|
wxVariant useValue = propgrid->GetPendingEditedValue();
|
||||||
|
|
||||||
wxArrayString labels = m_choices.GetLabels();
|
wxArrayString labels = m_choices.GetLabels();
|
||||||
unsigned int choiceCount;
|
unsigned int choiceCount;
|
||||||
@@ -1823,7 +1823,7 @@ bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid,
|
|||||||
|
|
||||||
dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
|
dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
|
||||||
|
|
||||||
wxArrayString strings = m_value.GetArrayString();
|
wxArrayString strings = useValue.GetArrayString();
|
||||||
wxArrayString extraStrings;
|
wxArrayString extraStrings;
|
||||||
|
|
||||||
dlg.SetSelections(m_choices.GetIndicesForStrings(strings, &extraStrings));
|
dlg.SetSelections(m_choices.GetIndicesForStrings(strings, &extraStrings));
|
||||||
|
@@ -1412,12 +1412,6 @@ bool wxPGProperty::HasVisibleChildren() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxPGProperty::PrepareValueForDialogEditing( wxPropertyGrid* propGrid )
|
|
||||||
{
|
|
||||||
return propGrid->CommitChangesFromEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool wxPGProperty::RecreateEditor()
|
bool wxPGProperty::RecreateEditor()
|
||||||
{
|
{
|
||||||
wxPropertyGrid* pg = GetGrid();
|
wxPropertyGrid* pg = GetGrid();
|
||||||
|
@@ -2731,7 +2731,8 @@ bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags )
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue )
|
bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue,
|
||||||
|
int flags )
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Runs all validation functionality.
|
// Runs all validation functionality.
|
||||||
@@ -2800,34 +2801,37 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
|
|||||||
|
|
||||||
wxVariant evtChangingValue = value;
|
wxVariant evtChangingValue = value;
|
||||||
|
|
||||||
// FIXME: After proper ValueToString()s added, remove
|
if ( flags & SendEvtChanging )
|
||||||
// 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 = baseChangedProperty;
|
// FIXME: After proper ValueToString()s added, remove
|
||||||
if ( evtChangingProperty != p )
|
// 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 );
|
evtChangingProperty = baseChangedProperty;
|
||||||
|
if ( evtChangingProperty != p )
|
||||||
|
{
|
||||||
|
evtChangingProperty->AdaptListToValue( bcpPendingList, &evtChangingValue );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
evtChangingValue = pendingValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
evtChangingValue = pendingValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
|
if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
|
||||||
{
|
|
||||||
if ( changedProperty == m_selected )
|
|
||||||
{
|
{
|
||||||
wxWindow* editor = GetEditorControl();
|
if ( changedProperty == m_selected )
|
||||||
wxASSERT( editor->IsKindOf(CLASSINFO(wxTextCtrl)) );
|
{
|
||||||
evtChangingValue = wxStaticCast(editor, wxTextCtrl)->GetValue();
|
wxWindow* editor = GetEditorControl();
|
||||||
}
|
wxASSERT( editor->IsKindOf(CLASSINFO(wxTextCtrl)) );
|
||||||
else
|
evtChangingValue = wxStaticCast(editor, wxTextCtrl)->GetValue();
|
||||||
{
|
}
|
||||||
wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
|
else
|
||||||
|
{
|
||||||
|
wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2849,9 +2853,20 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendEvent returns true if event was vetoed
|
if ( flags & SendEvtChanging )
|
||||||
if ( SendEvent( wxEVT_PG_CHANGING, evtChangingProperty, &evtChangingValue, 0 ) )
|
{
|
||||||
return false;
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -3089,6 +3104,30 @@ bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id, wxVariant newValue )
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
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
|
// Runs wxValidator for the selected property
|
||||||
bool wxPropertyGrid::DoEditorValidate()
|
bool wxPropertyGrid::DoEditorValidate()
|
||||||
{
|
{
|
||||||
|
@@ -1558,8 +1558,6 @@ wxValidator* wxDirProperty::DoGetValidator() const
|
|||||||
bool wxDirProperty::OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
|
bool wxDirProperty::OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
|
||||||
{
|
{
|
||||||
// Update property value from editor, if necessary
|
// Update property value from editor, if necessary
|
||||||
PrepareValueForDialogEditing(propGrid);
|
|
||||||
|
|
||||||
wxSize dlg_sz(300,400);
|
wxSize dlg_sz(300,400);
|
||||||
|
|
||||||
wxDirDialog dlg( propGrid,
|
wxDirDialog dlg( propGrid,
|
||||||
@@ -1887,9 +1885,9 @@ bool wxLongStringProperty::OnEvent( wxPropertyGrid* propGrid, wxWindow* WXUNUSED
|
|||||||
if ( propGrid->IsMainButtonEvent(event) )
|
if ( propGrid->IsMainButtonEvent(event) )
|
||||||
{
|
{
|
||||||
// Update the value
|
// Update the value
|
||||||
PrepareValueForDialogEditing(propGrid);
|
wxVariant useValue = propGrid->GetPendingEditedValue();
|
||||||
|
|
||||||
wxString val1 = GetValueAsString(0);
|
wxString val1 = useValue.GetString();
|
||||||
wxString val_orig = val1;
|
wxString val_orig = val1;
|
||||||
|
|
||||||
wxString value;
|
wxString value;
|
||||||
@@ -2489,7 +2487,7 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
|
|||||||
const wxChar* cbt )
|
const wxChar* cbt )
|
||||||
{
|
{
|
||||||
// Update the value
|
// Update the value
|
||||||
PrepareValueForDialogEditing(propGrid);
|
wxVariant useValue = propGrid->GetPendingEditedValue();
|
||||||
|
|
||||||
if ( !propGrid->EditorValidate() )
|
if ( !propGrid->EditorValidate() )
|
||||||
return false;
|
return false;
|
||||||
@@ -2506,7 +2504,7 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
|
|||||||
if ( strEdDlg )
|
if ( strEdDlg )
|
||||||
strEdDlg->SetCustomButton(cbt, this);
|
strEdDlg->SetCustomButton(cbt, this);
|
||||||
|
|
||||||
dlg->SetDialogValue( wxVariant(m_value) );
|
dlg->SetDialogValue( useValue );
|
||||||
dlg->Create(propGrid, wxEmptyString, m_label);
|
dlg->Create(propGrid, wxEmptyString, m_label);
|
||||||
|
|
||||||
#if !wxPG_SMALL_SCREEN
|
#if !wxPG_SMALL_SCREEN
|
||||||
|
Reference in New Issue
Block a user