valtext.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/valtext.h
  3. // Purpose: wxTextValidator class
  4. // Author: Julian Smart
  5. // Modified by: Francesco Montorsi
  6. // Created: 29/01/98
  7. // Copyright: (c) 1998 Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_VALTEXT_H_
  11. #define _WX_VALTEXT_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
  14. class WXDLLIMPEXP_FWD_CORE wxTextEntry;
  15. #include "wx/validate.h"
  16. enum wxTextValidatorStyle
  17. {
  18. wxFILTER_NONE = 0x0,
  19. wxFILTER_EMPTY = 0x1,
  20. wxFILTER_ASCII = 0x2,
  21. wxFILTER_ALPHA = 0x4,
  22. wxFILTER_ALPHANUMERIC = 0x8,
  23. wxFILTER_DIGITS = 0x10,
  24. wxFILTER_NUMERIC = 0x20,
  25. wxFILTER_INCLUDE_LIST = 0x40,
  26. wxFILTER_INCLUDE_CHAR_LIST = 0x80,
  27. wxFILTER_EXCLUDE_LIST = 0x100,
  28. wxFILTER_EXCLUDE_CHAR_LIST = 0x200
  29. };
  30. class WXDLLIMPEXP_CORE wxTextValidator: public wxValidator
  31. {
  32. public:
  33. wxTextValidator(long style = wxFILTER_NONE, wxString *val = NULL);
  34. wxTextValidator(const wxTextValidator& val);
  35. virtual ~wxTextValidator(){}
  36. // Make a clone of this validator (or return NULL) - currently necessary
  37. // if you're passing a reference to a validator.
  38. // Another possibility is to always pass a pointer to a new validator
  39. // (so the calling code can use a copy constructor of the relevant class).
  40. virtual wxObject *Clone() const { return new wxTextValidator(*this); }
  41. bool Copy(const wxTextValidator& val);
  42. // Called when the value in the window must be validated.
  43. // This function can pop up an error message.
  44. virtual bool Validate(wxWindow *parent);
  45. // Called to transfer data to the window
  46. virtual bool TransferToWindow();
  47. // Called to transfer data from the window
  48. virtual bool TransferFromWindow();
  49. // Filter keystrokes
  50. void OnChar(wxKeyEvent& event);
  51. // ACCESSORS
  52. inline long GetStyle() const { return m_validatorStyle; }
  53. void SetStyle(long style);
  54. wxTextEntry *GetTextEntry();
  55. void SetCharIncludes(const wxString& chars);
  56. void SetIncludes(const wxArrayString& includes) { m_includes = includes; }
  57. inline wxArrayString& GetIncludes() { return m_includes; }
  58. void SetCharExcludes(const wxString& chars);
  59. void SetExcludes(const wxArrayString& excludes) { m_excludes = excludes; }
  60. inline wxArrayString& GetExcludes() { return m_excludes; }
  61. bool HasFlag(wxTextValidatorStyle style) const
  62. { return (m_validatorStyle & style) != 0; }
  63. protected:
  64. // returns true if all characters of the given string are present in m_includes
  65. bool ContainsOnlyIncludedCharacters(const wxString& val) const;
  66. // returns true if at least one character of the given string is present in m_excludes
  67. bool ContainsExcludedCharacters(const wxString& val) const;
  68. // returns the error message if the contents of 'val' are invalid
  69. virtual wxString IsValid(const wxString& val) const;
  70. protected:
  71. long m_validatorStyle;
  72. wxString* m_stringValue;
  73. wxArrayString m_includes;
  74. wxArrayString m_excludes;
  75. private:
  76. wxDECLARE_NO_ASSIGN_CLASS(wxTextValidator);
  77. DECLARE_DYNAMIC_CLASS(wxTextValidator)
  78. DECLARE_EVENT_TABLE()
  79. };
  80. #endif
  81. // wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
  82. #endif // _WX_VALTEXT_H_