Make wxPGValidationInfo class instead of struct, re-document it (used at least by derived wxPGProperty::ValidateValue())

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55949 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2008-09-29 16:23:38 +00:00
parent 673ae68a3c
commit 2a8312bced
4 changed files with 93 additions and 28 deletions

View File

@@ -346,25 +346,17 @@ wxPG_VFB_UNDEFINED = 0x80
typedef wxByte wxPGVFBFlags; typedef wxByte wxPGVFBFlags;
/** @class wxPGValidationInfo /**
wxPGValidationInfo
Used to convey validation information to and from functions that Used to convey validation information to and from functions that
actually perform validation. actually perform validation. Mostly used in custom property
classes.
*/ */
struct wxPGValidationInfo class wxPGValidationInfo
{ {
/** Value to be validated. friend class wxPropertyGrid;
*/ public:
wxVariant* m_pValue;
/** Message displayed on validation failure.
*/
wxString m_failureMessage;
/** Validation failure behavior. Use wxPG_VFB_XXX flags.
*/
wxPGVFBFlags m_failureBehavior;
/** /**
@return Returns failure behavior which is a combination of @return Returns failure behavior which is a combination of
@ref propgrid_vfbflags. @ref propgrid_vfbflags.
@@ -377,6 +369,15 @@ struct wxPGValidationInfo
const wxString& GetFailureMessage() const const wxString& GetFailureMessage() const
{ return m_failureMessage; } { return m_failureMessage; }
/**
Returns reference to pending value.
*/
const wxVariant& GetValue() const
{
wxASSERT(m_pValue);
return *m_pValue;
}
/** Set validation failure behavior /** Set validation failure behavior
@param failureBehavior @param failureBehavior
@@ -389,6 +390,19 @@ struct wxPGValidationInfo
Set current failure message. Set current failure message.
*/ */
void SetFailureMessage(const wxString& message); void SetFailureMessage(const wxString& message);
private:
/** Value to be validated.
*/
wxVariant* m_pValue;
/** Message displayed on validation failure.
*/
wxString m_failureMessage;
/** Validation failure behavior. Use wxPG_VFB_XXX flags.
*/
wxPGVFBFlags m_failureBehavior;
}; };
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -2017,7 +2031,7 @@ public:
wxASSERT_MSG( m_validationInfo, wxASSERT_MSG( m_validationInfo,
"Only call GetValue from a handler " "Only call GetValue from a handler "
"of event type that supports it" ); "of event type that supports it" );
return *m_validationInfo->m_pValue; return m_validationInfo->GetValue();
} }
/** /**
@@ -2026,10 +2040,10 @@ public:
Only effective if Veto was also called, and only allowed if event type Only effective if Veto was also called, and only allowed if event type
is wxEVT_PG_CHANGING. is wxEVT_PG_CHANGING.
*/ */
void SetValidationFailureBehavior( int flags ) void SetValidationFailureBehavior( wxPGVFBFlags flags )
{ {
wxASSERT( GetEventType() == wxEVT_PG_CHANGING ); wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
m_validationInfo->m_failureBehavior = (wxPGVFBFlags) flags; m_validationInfo->SetFailureBehavior( flags );
} }
/** Sets custom failure message for this time only. Only applies if /** Sets custom failure message for this time only. Only applies if
@@ -2038,14 +2052,14 @@ public:
void SetValidationFailureMessage( const wxString& message ) void SetValidationFailureMessage( const wxString& message )
{ {
wxASSERT( GetEventType() == wxEVT_PG_CHANGING ); wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
m_validationInfo->m_failureMessage = message; m_validationInfo->SetFailureMessage( message );
} }
#ifndef SWIG #ifndef SWIG
wxPGVFBFlags GetValidationFailureBehavior() const wxPGVFBFlags GetValidationFailureBehavior() const
{ {
wxASSERT( GetEventType() == wxEVT_PG_CHANGING ); wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
return m_validationInfo->m_failureBehavior; return m_validationInfo->GetFailureBehavior();
} }
void SetCanVeto( bool canVeto ) { m_canVeto = canVeto; } void SetCanVeto( bool canVeto ) { m_canVeto = canVeto; }

View File

@@ -269,7 +269,7 @@ class wxPropertyGridManager;
class wxPGOwnerDrawnComboBox; class wxPGOwnerDrawnComboBox;
class wxPGCustomComboControl; class wxPGCustomComboControl;
class wxPGEditorDialogAdapter; class wxPGEditorDialogAdapter;
struct wxPGValidationInfo; class wxPGValidationInfo;
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View File

@@ -215,6 +215,45 @@ wxPG_VFB_DEFAULT = wxPG_VFB_STAY_IN_PROPERTY|wxPG_VFB_BEEP,
typedef wxByte wxPGVFBFlags; typedef wxByte wxPGVFBFlags;
/**
wxPGValidationInfo
Used to convey validation information to and from functions that
actually perform validation. Mostly used in custom property
classes.
*/
class wxPGValidationInfo
{
public:
/**
@return Returns failure behavior which is a combination of
@ref propgrid_vfbflags.
*/
wxPGVFBFlags GetFailureBehavior();
/**
Returns current failure message.
*/
const wxString& GetFailureMessage() const;
/**
Returns reference to pending value.
*/
const wxVariant& GetValue() const;
/** Set validation failure behavior
@param failureBehavior
Mixture of @ref propgrid_vfbflags.
*/
void SetFailureBehavior(wxPGVFBFlags failureBehavior);
/**
Set current failure message.
*/
void SetFailureMessage(const wxString& message);
};
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
/** /**
@@ -877,7 +916,7 @@ public:
Set override validation failure behavior. Only effective if Veto() was Set override validation failure behavior. Only effective if Veto() was
also called, and only allowed if event type is wxEVT_PG_CHANGING. also called, and only allowed if event type is wxEVT_PG_CHANGING.
*/ */
void SetValidationFailureBehavior( int flags ); void SetValidationFailureBehavior( wxPGVFBFlags flags );
/** /**
Sets custom failure message for this time only. Only applies if Sets custom failure message for this time only. Only applies if

View File

@@ -281,7 +281,9 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& va
if ( value < min ) if ( value < min )
{ {
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
pValidationInfo->m_failureMessage = wxString::Format(_("Value must be %lld or higher"),min); pValidationInfo->SetFailureMessage(
wxString::Format(_("Value must be %lld or higher"),min)
);
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
value = min; value = min;
else else
@@ -295,7 +297,9 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& va
if ( value > max ) if ( value > max )
{ {
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
pValidationInfo->m_failureMessage = wxString::Format(_("Value must be %lld or higher"),min); pValidationInfo->SetFailureMessage(
wxString::Format(_("Value must be %lld or higher"),min)
);
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
value = max; value = max;
else else
@@ -488,7 +492,9 @@ bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& valida
wxPGVariantToULongLong(variant, &min); wxPGVariantToULongLong(variant, &min);
if ( ll < min ) if ( ll < min )
{ {
validationInfo.m_failureMessage = wxString::Format(_("Value must be %llu or higher"),min); validationInfo.SetFailureMessage(
wxString::Format(_("Value must be %llu or higher"),min)
);
return false; return false;
} }
} }
@@ -498,7 +504,9 @@ bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& valida
wxPGVariantToULongLong(variant, &max); wxPGVariantToULongLong(variant, &max);
if ( ll > max ) if ( ll > max )
{ {
validationInfo.m_failureMessage = wxString::Format(_("Value must be %llu or less"),max); validationInfo.SetFailureMessage(
wxString::Format(_("Value must be %llu or less"),max)
);
return false; return false;
} }
} }
@@ -672,7 +680,9 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property, double& value,
if ( value < min ) if ( value < min )
{ {
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
pValidationInfo->m_failureMessage = wxString::Format(_("Value must be %f or higher"),min); pValidationInfo->SetFailureMessage(
wxString::Format(_("Value must be %f or higher"),min)
);
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
value = min; value = min;
else else
@@ -687,7 +697,9 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property, double& value,
if ( value > max ) if ( value > max )
{ {
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
pValidationInfo->m_failureMessage = wxString::Format(_("Value must be %f or less"),max); pValidationInfo->SetFailureMessage(
wxString::Format(_("Value must be %f or less"),max)
);
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
value = max; value = max;
else else