/// Use an include list. The validator checks if each input character is
/// in the list (one character per list element), complaining if not.
- /// See wxTextValidator::SetIncludes().
+ /// See wxTextValidator::SetCharIncludes().
wxFILTER_INCLUDE_CHAR_LIST,
- /// Use an include list. The validator checks if each input character is
+ /// Use an exclude list. The validator checks if each input character is
/// in the list (one character per list element), complaining if it is.
- /// See wxTextValidator::SetExcludes().
+ /// See wxTextValidator::SetCharExcludes().
wxFILTER_EXCLUDE_CHAR_LIST
};
*/
void SetExcludes(const wxArrayString& stringList);
+ /**
+ Breaks the given @a chars strings in single characters and sets the
+ internal wxArrayString used to store the "excluded" characters
+ (see SetExcludes()).
+
+ This function is mostly useful when @c wxFILTER_EXCLUDE_CHAR_LIST was used.
+ */
+ void SetCharExcludes(const wxString& chars);
+
/**
Sets the include list (valid values for the user input).
*/
void SetIncludes(const wxArrayString& stringList);
+ /**
+ Breaks the given @a chars strings in single characters and sets the
+ internal wxArrayString used to store the "included" characters
+ (see SetIncludes()).
+
+ This function is mostly useful when @c wxFILTER_INCLUDE_CHAR_LIST was used.
+ */
+ void SetCharIncludes(const wxString& chars);
+
/**
Sets the validator style.
*/
// will complain because spaces aren't alpha. Note that validation
// is performed only when 'OK' is pressed.
m_string = wxT("Spaces are invalid here");
+ m_string2 = "Valid text";
m_listbox_choices.Add(0);
}
-
// ----------------------------------------------------------------------------
// MyComboBoxValidator
// ----------------------------------------------------------------------------
wxMenu *file_menu = new wxMenu;
- file_menu->Append(VALIDATE_TEST_DIALOG, wxT("&Test"), wxT("Demonstrate validators"));
+ file_menu->Append(VALIDATE_TEST_DIALOG, wxT("&Test dialog..."), wxT("Demonstrate validators"));
file_menu->AppendCheckItem(VALIDATE_TOGGLE_BELL, wxT("&Bell on error"), wxT("Toggle bell on error"));
file_menu->AppendSeparator();
file_menu->Append(wxID_EXIT, wxT("E&xit"));
// when we created the validators.
m_listbox->Clear();
m_listbox->Append(wxString(_T("string: ")) + g_data.m_string);
+ m_listbox->Append(wxString(_T("string #2: ")) + g_data.m_string2);
+
for(unsigned int i = 0; i < g_data.m_listbox_choices.GetCount(); ++i)
{
int j = g_data.m_listbox_choices[i];
// setup the flex grid sizer
// -------------------------
- wxFlexGridSizer *flexgridsizer = new wxFlexGridSizer(2, 2, 5, 5);
+ wxFlexGridSizer *flexgridsizer = new wxFlexGridSizer(3, 2, 5, 5);
// Create and add controls to sizers. Note that a member variable
// of g_data is bound to each control upon construction. There is
wxTextValidator(wxFILTER_ALPHA, &g_data.m_string));
flexgridsizer->Add(m_text, 1, wxGROW);
- // This wxCheckBox* doesn't need to be assigned to any pointer
- // because we don't use it elsewhere--it can be anonymous.
- // We don't need any such pointer to query its state, which
- // can be gotten directly from g_data.
- flexgridsizer->Add(new wxCheckBox(this, VALIDATE_CHECK, wxT("Sample checkbox"),
- wxPoint(130, 10), wxSize(120, wxDefaultCoord), 0,
- wxGenericValidator(&g_data.m_checkbox_state)),
- 1, wxALIGN_CENTER);
+
+ // Now set a wxTextValidator with an explicit list of characters NOT allowed:
+ wxTextValidator textVal(wxFILTER_EXCLUDE_CHAR_LIST, &g_data.m_string2);
+ textVal.SetCharExcludes("bcwyz");
+ flexgridsizer->Add(new wxTextCtrl(this, VALIDATE_TEXT2, wxEmptyString,
+ wxDefaultPosition, wxDefaultSize, 0, textVal),
+ 1, wxGROW);
flexgridsizer->Add(new wxListBox((wxWindow*)this, VALIDATE_LIST,
wxPoint(10, 30), wxSize(120, wxDefaultCoord),
MyComboBoxValidator(&g_data.m_combobox_choice));
flexgridsizer->Add(m_combobox, 1, wxALIGN_CENTER);
+ // This wxCheckBox* doesn't need to be assigned to any pointer
+ // because we don't use it elsewhere--it can be anonymous.
+ // We don't need any such pointer to query its state, which
+ // can be gotten directly from g_data.
+ flexgridsizer->Add(new wxCheckBox(this, VALIDATE_CHECK, wxT("Sample checkbox"),
+ wxPoint(130, 10), wxSize(120, wxDefaultCoord), 0,
+ wxGenericValidator(&g_data.m_checkbox_state)),
+ 1, wxALIGN_CENTER);
+
flexgridsizer->AddGrowableCol(0);
flexgridsizer->AddGrowableCol(1);
flexgridsizer->AddGrowableRow(1);
bool wxTextValidator::ContainsOnlyIncludedCharacters(const wxString& val) const
{
- for (size_t i = 0; i < val.length(); i++)
- if (m_includes.Index((wxString) val[i]) == wxNOT_FOUND)
+ for ( wxString::const_iterator i = val.begin(); i != val.end(); ++i )
+ if (m_includes.Index((wxString) *i) == wxNOT_FOUND)
// one character of 'val' is NOT present in m_includes...
return false;
bool wxTextValidator::ContainsExcludedCharacters(const wxString& val) const
{
- for (size_t i = 0; i < val.length(); i++)
- if (m_excludes.Index((wxString) val[i]) != wxNOT_FOUND)
+ for ( wxString::const_iterator i = val.begin(); i != val.end(); ++i )
+ if (m_excludes.Index((wxString) *i) != wxNOT_FOUND)
// one character of 'val' is present in m_excludes...
- return false;
+ return true;
// all characters of 'val' are NOT present in m_excludes
- return true;
+ return false;
+}
+
+void wxTextValidator::SetCharIncludes(const wxString& chars)
+{
+ wxArrayString arr;
+
+ for ( wxString::const_iterator i = chars.begin(); i != chars.end(); ++i )
+ arr.Add(*i);
+
+ SetIncludes(arr);
+}
+
+void wxTextValidator::SetCharExcludes(const wxString& chars)
+{
+ wxArrayString arr;
+
+ for ( wxString::const_iterator i = chars.begin(); i != chars.end(); ++i )
+ arr.Add(*i);
+
+ SetExcludes(arr);
}
void wxTextValidator::OnChar(wxKeyEvent& event)