Code: Select all
class PostalValidator: public wxTextValidator
{
public:
PostalValidator() :
wxTextValidator(wxFILTER_INCLUDE_LIST)
{
wxString postalchars[11] =
{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-" };
wxArrayString as(11, postalchars);
SetIncludes(as);
}
protected:
wxObject* Clone() const
{
return new PostalValidator();
}
bool checkDash(const wxString& str)
{
if(str.Len()>=3 && str[2]!='-')
return false;
else return true;
}
virtual bool TransferToWindow()
{
if (checkDash(*m_stringValue))
return wxTextValidator::TransferToWindow();
else
return false;
}
virtual bool TransferFromWindow(void)
{
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow;
const wxString& tempString = control->GetValue();
if (checkDash(tempString))
return wxTextValidator::TransferFromWindow();
else return false;
}
};
ContractorPanel::ContractorPanel(bool createNew, wxWindow* parent,
wxWindowID id, const wxPoint& pos, const wxSize& size, long style) :
fb_ConrtractorForm(parent, id, pos, size, style)
{
mCreateNew = createNew;
m_textPostal->SetValidator(PostalValidator());
}