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:
parent
483b6cf0d4
commit
9b5bafcf38
@ -1814,23 +1814,6 @@ public:
|
||||
}
|
||||
#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.
|
||||
*/
|
||||
|
@ -832,6 +832,14 @@ public:
|
||||
/** 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;
|
||||
|
||||
@ -1257,12 +1265,6 @@ public:
|
||||
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.
|
||||
@ -1340,6 +1342,21 @@ protected:
|
||||
*/
|
||||
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:
|
||||
|
||||
|
@ -240,9 +240,6 @@
|
||||
@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,
|
||||
@ -1199,24 +1196,6 @@ public:
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -586,6 +586,14 @@ public:
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -131,11 +131,10 @@ bool wxFontDataProperty::OnEvent( wxPropertyGrid* propgrid,
|
||||
{
|
||||
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());
|
||||
|
||||
@ -554,10 +553,10 @@ bool wxArrayDoubleProperty::OnEvent( wxPropertyGrid* propgrid,
|
||||
{
|
||||
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;
|
||||
|
@ -531,11 +531,11 @@ bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(prima
|
||||
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);
|
||||
|
||||
@ -1803,7 +1803,7 @@ bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid,
|
||||
if ( propgrid->IsMainButtonEvent(event) )
|
||||
{
|
||||
// Update the value
|
||||
PrepareValueForDialogEditing(propgrid);
|
||||
wxVariant useValue = propgrid->GetPendingEditedValue();
|
||||
|
||||
wxArrayString labels = m_choices.GetLabels();
|
||||
unsigned int choiceCount;
|
||||
@ -1823,7 +1823,7 @@ bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid,
|
||||
|
||||
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));
|
||||
|
@ -1412,12 +1412,6 @@ bool wxPGProperty::HasVisibleChildren() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxPGProperty::PrepareValueForDialogEditing( wxPropertyGrid* propGrid )
|
||||
{
|
||||
return propGrid->CommitChangesFromEditor();
|
||||
}
|
||||
|
||||
|
||||
bool wxPGProperty::RecreateEditor()
|
||||
{
|
||||
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.
|
||||
@ -2800,34 +2801,37 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
|
||||
|
||||
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 );
|
||||
evtChangingProperty = baseChangedProperty;
|
||||
if ( evtChangingProperty != p )
|
||||
{
|
||||
evtChangingProperty->AdaptListToValue( bcpPendingList, &evtChangingValue );
|
||||
}
|
||||
else
|
||||
{
|
||||
evtChangingValue = pendingValue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
evtChangingValue = pendingValue;
|
||||
}
|
||||
}
|
||||
|
||||
if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
|
||||
{
|
||||
if ( changedProperty == m_selected )
|
||||
if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
|
||||
{
|
||||
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."));
|
||||
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."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2849,9 +2853,20 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
|
||||
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;
|
||||
}
|
||||
@ -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
|
||||
bool wxPropertyGrid::DoEditorValidate()
|
||||
{
|
||||
|
@ -1558,8 +1558,6 @@ wxValidator* wxDirProperty::DoGetValidator() const
|
||||
bool wxDirProperty::OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
|
||||
{
|
||||
// Update property value from editor, if necessary
|
||||
PrepareValueForDialogEditing(propGrid);
|
||||
|
||||
wxSize dlg_sz(300,400);
|
||||
|
||||
wxDirDialog dlg( propGrid,
|
||||
@ -1887,9 +1885,9 @@ bool wxLongStringProperty::OnEvent( wxPropertyGrid* propGrid, wxWindow* WXUNUSED
|
||||
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;
|
||||
@ -2489,7 +2487,7 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
|
||||
const wxChar* cbt )
|
||||
{
|
||||
// Update the value
|
||||
PrepareValueForDialogEditing(propGrid);
|
||||
wxVariant useValue = propGrid->GetPendingEditedValue();
|
||||
|
||||
if ( !propGrid->EditorValidate() )
|
||||
return false;
|
||||
@ -2506,7 +2504,7 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
|
||||
if ( strEdDlg )
|
||||
strEdDlg->SetCustomButton(cbt, this);
|
||||
|
||||
dlg->SetDialogValue( wxVariant(m_value) );
|
||||
dlg->SetDialogValue( useValue );
|
||||
dlg->Create(propGrid, wxEmptyString, m_label);
|
||||
|
||||
#if !wxPG_SMALL_SCREEN
|
||||
|
Loading…
Reference in New Issue
Block a user