wxTextValidator improvements

Improve char inclusion/exclusion support; update the sample to show more
features of this class and add a unit test for it.

Closes https://github.com/wxWidgets/wxWidgets/pull/1093
This commit is contained in:
ali kettab
2019-01-01 00:55:14 +01:00
committed by Vadim Zeitlin
parent 697125dc03
commit 36f6f8ad49
18 changed files with 1000 additions and 247 deletions

View File

@@ -48,7 +48,8 @@ public:
const wxSize& size = wxDefaultSize,
const long style = wxDEFAULT_DIALOG_STYLE);
bool TransferDataToWindow() wxOVERRIDE;
void OnChangeValidator(wxCommandEvent& event);
wxTextCtrl *m_text;
wxComboBox *m_combobox;
@@ -56,6 +57,81 @@ public:
wxTextCtrl *m_numericTextDouble;
};
// ----------------------------------------------------------------------------
// TextValidatorDialog
// ----------------------------------------------------------------------------
class TextValidatorDialog : public wxDialog
{
public:
TextValidatorDialog(wxWindow *parent, wxTextCtrl* txtCtrl);
void OnUpdateUI(wxUpdateUIEvent& event);
void OnChecked(wxCommandEvent& event);
void OnKillFocus( wxFocusEvent &event );
void ApplyValidator();
private:
// Special validator for our checkboxes
class StyleValidator : public wxValidator
{
public:
StyleValidator(long* style) { m_style = style; }
virtual bool Validate(wxWindow *WXUNUSED(parent)) wxOVERRIDE { return true; }
virtual wxObject* Clone() const wxOVERRIDE { return new StyleValidator(*this); }
// Called to transfer data to the window
virtual bool TransferToWindow() wxOVERRIDE;
// Called to transfer data from the window
virtual bool TransferFromWindow() wxOVERRIDE;
private:
long* m_style;
};
private:
bool HasFlag(wxTextValidatorStyle style) const
{
return (m_validatorStyle & style) != 0;
}
enum
{
// CheckBoxes Ids (should be in sync with wxTextValidatorStyle)
Id_None = wxID_HIGHEST,
Id_Empty,
Id_Ascii,
Id_Alpha,
Id_Alphanumeric,
Id_Digits,
Id_Numeric,
Id_IncludeList,
Id_IncludeCharList,
Id_ExcludeList,
Id_ExcludeCharList,
Id_Xdigits,
Id_Space,
// TextCtrls Ids
Id_IncludeListTxt,
Id_IncludeCharListTxt,
Id_ExcludeListTxt,
Id_ExcludeCharListTxt,
};
wxTextCtrl* const m_txtCtrl;
bool m_noValidation;
long m_validatorStyle;
wxString m_charIncludes;
wxString m_charExcludes;
wxArrayString m_includes;
wxArrayString m_excludes;
};
class MyData
{
public: